mindspore 2.2.10__cp37-none-any.whl → 2.2.14__cp37-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mindspore might be problematic. Click here for more details.

Files changed (153) hide show
  1. mindspore/.commit_id +1 -1
  2. mindspore/__init__.py +2 -1
  3. mindspore/_akg/akg/composite/build_module.py +95 -5
  4. mindspore/_akg/akg/topi/cpp/impl.py +1 -1
  5. mindspore/_akg/akg/tvm/_ffi/base.py +1 -1
  6. mindspore/_akg/akg/utils/composite_op_helper.py +7 -2
  7. mindspore/_akg/akg/utils/dump_ascend_meta.py +22 -3
  8. mindspore/_akg/akg/utils/util.py +18 -1
  9. mindspore/_c_dataengine.cpython-37m-aarch64-linux-gnu.so +0 -0
  10. mindspore/_c_expression.cpython-37m-aarch64-linux-gnu.so +0 -0
  11. mindspore/_c_mindrecord.cpython-37m-aarch64-linux-gnu.so +0 -0
  12. mindspore/_extends/parse/__init__.py +3 -2
  13. mindspore/_extends/parse/parser.py +6 -1
  14. mindspore/_extends/parse/standard_method.py +12 -2
  15. mindspore/_mindspore_offline_debug.cpython-37m-aarch64-linux-gnu.so +0 -0
  16. mindspore/bin/cache_admin +0 -0
  17. mindspore/bin/cache_server +0 -0
  18. mindspore/common/_utils.py +16 -0
  19. mindspore/common/tensor.py +0 -2
  20. mindspore/communication/management.py +3 -0
  21. mindspore/context.py +34 -4
  22. mindspore/dataset/engine/cache_client.py +8 -5
  23. mindspore/dataset/engine/datasets.py +23 -0
  24. mindspore/dataset/engine/validators.py +1 -1
  25. mindspore/dataset/vision/py_transforms_util.py +2 -2
  26. mindspore/experimental/optim/lr_scheduler.py +5 -6
  27. mindspore/lib/libdnnl.so.2 +0 -0
  28. mindspore/lib/libmindspore.so +0 -0
  29. mindspore/lib/libmindspore_backend.so +0 -0
  30. mindspore/lib/libmindspore_common.so +0 -0
  31. mindspore/lib/libmindspore_core.so +0 -0
  32. mindspore/lib/libmindspore_glog.so.0 +0 -0
  33. mindspore/lib/libmindspore_gpr.so.15 +0 -0
  34. mindspore/lib/libmindspore_grpc++.so.1 +0 -0
  35. mindspore/lib/libmindspore_grpc.so.15 +0 -0
  36. mindspore/lib/libmindspore_shared_lib.so +0 -0
  37. mindspore/lib/libopencv_core.so.4.5 +0 -0
  38. mindspore/lib/libopencv_imgcodecs.so.4.5 +0 -0
  39. mindspore/lib/libopencv_imgproc.so.4.5 +0 -0
  40. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_aicpu_kernels.so +0 -0
  41. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl/libcust_cpu_kernels.so +0 -0
  42. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_impl/cpu/config/cust_aicpu_kernel.json +118 -0
  43. mindspore/lib/plugin/ascend/custom_aicpu_ops/op_proto/libcust_op_proto.so +0 -0
  44. mindspore/lib/plugin/ascend/libakg.so +0 -0
  45. mindspore/lib/plugin/ascend/libascend_collective.so +0 -0
  46. mindspore/lib/plugin/ascend/libdvpp_utils.so +0 -0
  47. mindspore/lib/plugin/ascend/libmindspore_aicpu_kernels.so +0 -0
  48. mindspore/lib/plugin/ascend/libmindspore_cpu_kernels.so +0 -0
  49. mindspore/lib/plugin/cpu/libakg.so +0 -0
  50. mindspore/lib/plugin/libmindspore_ascend.so.1 +0 -0
  51. mindspore/mindrecord/tools/cifar100_to_mr.py +49 -57
  52. mindspore/mindrecord/tools/cifar10_to_mr.py +46 -55
  53. mindspore/mindrecord/tools/csv_to_mr.py +3 -8
  54. mindspore/mindrecord/tools/mnist_to_mr.py +4 -9
  55. mindspore/mindrecord/tools/tfrecord_to_mr.py +1 -4
  56. mindspore/nn/layer/activation.py +1 -1
  57. mindspore/nn/layer/embedding.py +2 -2
  58. mindspore/nn/layer/flash_attention.py +48 -135
  59. mindspore/nn/loss/loss.py +1 -1
  60. mindspore/nn/optim/ada_grad.py +2 -2
  61. mindspore/nn/optim/sgd.py +3 -2
  62. mindspore/nn/wrap/__init__.py +4 -2
  63. mindspore/nn/wrap/cell_wrapper.py +6 -3
  64. mindspore/numpy/math_ops.py +1 -1
  65. mindspore/ops/__init__.py +3 -0
  66. mindspore/ops/_grad_experimental/grad_array_ops.py +0 -31
  67. mindspore/ops/_grad_experimental/grad_comm_ops.py +4 -2
  68. mindspore/ops/_grad_experimental/grad_inner_ops.py +8 -0
  69. mindspore/ops/_grad_experimental/grad_math_ops.py +37 -17
  70. mindspore/ops/_op_impl/aicpu/__init__.py +1 -0
  71. mindspore/ops/_op_impl/aicpu/generate_eod_mask.py +38 -0
  72. mindspore/ops/_op_impl/aicpu/linear_sum_assignment.py +21 -2
  73. mindspore/ops/function/array_func.py +6 -5
  74. mindspore/ops/function/debug_func.py +1 -1
  75. mindspore/ops/function/linalg_func.py +21 -11
  76. mindspore/ops/function/math_func.py +3 -0
  77. mindspore/ops/function/nn_func.py +13 -11
  78. mindspore/ops/function/parameter_func.py +2 -0
  79. mindspore/ops/function/sparse_unary_func.py +2 -2
  80. mindspore/ops/function/vmap_func.py +1 -0
  81. mindspore/ops/operations/__init__.py +5 -2
  82. mindspore/ops/operations/_embedding_cache_ops.py +1 -1
  83. mindspore/ops/operations/_grad_ops.py +3 -4
  84. mindspore/ops/operations/_inner_ops.py +56 -1
  85. mindspore/ops/operations/_quant_ops.py +4 -4
  86. mindspore/ops/operations/_rl_inner_ops.py +1 -1
  87. mindspore/ops/operations/array_ops.py +15 -4
  88. mindspore/ops/operations/custom_ops.py +1 -1
  89. mindspore/ops/operations/debug_ops.py +1 -1
  90. mindspore/ops/operations/image_ops.py +3 -3
  91. mindspore/ops/operations/inner_ops.py +49 -0
  92. mindspore/ops/operations/math_ops.py +65 -3
  93. mindspore/ops/operations/nn_ops.py +95 -28
  94. mindspore/ops/operations/random_ops.py +2 -0
  95. mindspore/ops/operations/sparse_ops.py +4 -4
  96. mindspore/ops/silent_check.py +162 -0
  97. mindspore/parallel/__init__.py +3 -2
  98. mindspore/parallel/_auto_parallel_context.py +82 -3
  99. mindspore/parallel/_parallel_serialization.py +34 -2
  100. mindspore/parallel/_tensor.py +3 -1
  101. mindspore/parallel/_transformer/transformer.py +8 -8
  102. mindspore/parallel/checkpoint_transform.py +191 -45
  103. mindspore/profiler/parser/ascend_cluster_generator.py +111 -0
  104. mindspore/profiler/parser/ascend_communicate_generator.py +315 -0
  105. mindspore/profiler/parser/ascend_flops_generator.py +8 -2
  106. mindspore/profiler/parser/ascend_fpbp_generator.py +8 -2
  107. mindspore/profiler/parser/ascend_hccl_generator.py +2 -2
  108. mindspore/profiler/parser/ascend_msprof_exporter.py +30 -6
  109. mindspore/profiler/parser/ascend_msprof_generator.py +16 -5
  110. mindspore/profiler/parser/ascend_op_generator.py +15 -7
  111. mindspore/profiler/parser/ascend_timeline_generator.py +5 -2
  112. mindspore/profiler/parser/base_timeline_generator.py +11 -3
  113. mindspore/profiler/parser/cpu_gpu_timeline_generator.py +2 -1
  114. mindspore/profiler/parser/framework_parser.py +8 -2
  115. mindspore/profiler/parser/memory_usage_parser.py +8 -2
  116. mindspore/profiler/parser/minddata_analyzer.py +8 -2
  117. mindspore/profiler/parser/minddata_parser.py +1 -1
  118. mindspore/profiler/parser/msadvisor_analyzer.py +4 -2
  119. mindspore/profiler/parser/msadvisor_parser.py +9 -3
  120. mindspore/profiler/profiling.py +97 -25
  121. mindspore/rewrite/api/node.py +1 -1
  122. mindspore/rewrite/api/symbol_tree.py +2 -2
  123. mindspore/rewrite/parsers/for_parser.py +6 -6
  124. mindspore/rewrite/parsers/module_parser.py +4 -4
  125. mindspore/scipy/ops.py +55 -5
  126. mindspore/scipy/optimize/__init__.py +3 -2
  127. mindspore/scipy/optimize/linear_sum_assignment.py +38 -33
  128. mindspore/train/callback/_checkpoint.py +8 -8
  129. mindspore/train/callback/_landscape.py +2 -3
  130. mindspore/train/callback/_summary_collector.py +6 -7
  131. mindspore/train/dataset_helper.py +6 -0
  132. mindspore/train/model.py +17 -5
  133. mindspore/train/serialization.py +6 -1
  134. mindspore/train/summary/_writer_pool.py +1 -1
  135. mindspore/train/summary/summary_record.py +5 -6
  136. mindspore/version.py +1 -1
  137. {mindspore-2.2.10.dist-info → mindspore-2.2.14.dist-info}/METADATA +3 -2
  138. {mindspore-2.2.10.dist-info → mindspore-2.2.14.dist-info}/RECORD +141 -149
  139. mindspore/lib/plugin/libmindspore_ascend.so.2 +0 -0
  140. mindspore/ops/_op_impl/_custom_op/flash_attention/__init__.py +0 -0
  141. mindspore/ops/_op_impl/_custom_op/flash_attention/attention.py +0 -406
  142. mindspore/ops/_op_impl/_custom_op/flash_attention/constants.py +0 -41
  143. mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_bwd.py +0 -467
  144. mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_fwd.py +0 -563
  145. mindspore/ops/_op_impl/_custom_op/flash_attention/flash_attention_impl.py +0 -193
  146. mindspore/ops/_op_impl/_custom_op/flash_attention/tik_ops_utils.py +0 -435
  147. mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/__init__.py +0 -0
  148. mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/sparse_tiling.py +0 -45
  149. mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/strategy.py +0 -67
  150. mindspore/ops/_op_impl/_custom_op/flash_attention/tiling_strategy/wukong_tiling.py +0 -62
  151. {mindspore-2.2.10.dist-info → mindspore-2.2.14.dist-info}/WHEEL +0 -0
  152. {mindspore-2.2.10.dist-info → mindspore-2.2.14.dist-info}/entry_points.txt +0 -0
  153. {mindspore-2.2.10.dist-info → mindspore-2.2.14.dist-info}/top_level.txt +0 -0
@@ -2913,6 +2913,30 @@
2913
2913
  "type":"DT_INT32,DT_INT64"
2914
2914
  }
2915
2915
  },
2916
+ "CustGenerateEodMask":{
2917
+ "input0":{
2918
+ "name":"inputs_ids",
2919
+ "type":"DT_INT32,DT_DOUBLE,DT_FLOAT,DT_FLOAT16,DT_BF16"
2920
+ },
2921
+ "opInfo":{
2922
+ "computeCost":"100",
2923
+ "engine":"DNN_VM_AICPU",
2924
+ "flagAsync":"False",
2925
+ "flagPartial":"False",
2926
+ "formatAgnostic":"False",
2927
+ "functionName":"RunCpuKernel",
2928
+ "kernelSo":"libcust_cpu_kernels.so",
2929
+ "opKernelLib":"CUSTAICPUKernel",
2930
+ "opsFlag":"OPS_FLAG_CLOSE",
2931
+ "subTypeOfInferShape":"1",
2932
+ "userDefined":"True",
2933
+ "workspaceSize":"1024"
2934
+ },
2935
+ "output0":{
2936
+ "name":"position_ids",
2937
+ "type":"DT_INT32,DT_DOUBLE,DT_FLOAT,DT_FLOAT16,DT_BF16"
2938
+ }
2939
+ },
2916
2940
  "CustGeqrf":{
2917
2941
  "input0":{
2918
2942
  "name":"x",
@@ -3292,6 +3316,41 @@
3292
3316
  "type":"DT_DOUBLE,DT_FLOAT,DT_FLOAT16"
3293
3317
  }
3294
3318
  },
3319
+ "CustLinearSumAssignment":{
3320
+ "input0":{
3321
+ "name":"cost_matrix",
3322
+ "type":"DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT16,DT_INT32,DT_INT64,DT_INT8,DT_UINT16,DT_UINT32,DT_UINT64,DT_UINT8,DT_BOOL"
3323
+ },
3324
+ "input1":{
3325
+ "name":"dimension_limit",
3326
+ "type":"DT_INT64"
3327
+ },
3328
+ "input2":{
3329
+ "name":"maximize",
3330
+ "type":"DT_BOOL"
3331
+ },
3332
+ "opInfo":{
3333
+ "computeCost":"100",
3334
+ "engine":"DNN_VM_AICPU",
3335
+ "flagAsync":"False",
3336
+ "flagPartial":"False",
3337
+ "formatAgnostic":"False",
3338
+ "functionName":"RunCpuKernel",
3339
+ "kernelSo":"libcust_cpu_kernels.so",
3340
+ "opKernelLib":"CUSTAICPUKernel",
3341
+ "opsFlag":"OPS_FLAG_OPEN",
3342
+ "subTypeOfInferShape":"1",
3343
+ "userDefined":"True"
3344
+ },
3345
+ "output0":{
3346
+ "name":"row_ind",
3347
+ "type":"DT_INT64"
3348
+ },
3349
+ "output1":{
3350
+ "name":"col_ind",
3351
+ "type":"DT_INT64"
3352
+ }
3353
+ },
3295
3354
  "CustListDiff":{
3296
3355
  "input0":{
3297
3356
  "name":"x",
@@ -6225,6 +6284,30 @@
6225
6284
  "type":"DT_INT32,DT_INT64"
6226
6285
  }
6227
6286
  },
6287
+ "GenerateEodMask":{
6288
+ "input0":{
6289
+ "name":"inputs_ids",
6290
+ "type":"DT_INT32,DT_DOUBLE,DT_FLOAT,DT_FLOAT16,DT_BF16"
6291
+ },
6292
+ "opInfo":{
6293
+ "computeCost":"100",
6294
+ "engine":"DNN_VM_AICPU",
6295
+ "flagAsync":"False",
6296
+ "flagPartial":"False",
6297
+ "formatAgnostic":"False",
6298
+ "functionName":"RunCpuKernel",
6299
+ "kernelSo":"libcust_cpu_kernels.so",
6300
+ "opKernelLib":"CUSTAICPUKernel",
6301
+ "opsFlag":"OPS_FLAG_CLOSE",
6302
+ "subTypeOfInferShape":"1",
6303
+ "userDefined":"True",
6304
+ "workspaceSize":"1024"
6305
+ },
6306
+ "output0":{
6307
+ "name":"position_ids",
6308
+ "type":"DT_INT32,DT_DOUBLE,DT_FLOAT,DT_FLOAT16,DT_BF16"
6309
+ }
6310
+ },
6228
6311
  "Geqrf":{
6229
6312
  "input0":{
6230
6313
  "name":"x",
@@ -6604,6 +6687,41 @@
6604
6687
  "type":"DT_DOUBLE,DT_FLOAT,DT_FLOAT16"
6605
6688
  }
6606
6689
  },
6690
+ "LinearSumAssignment":{
6691
+ "input0":{
6692
+ "name":"cost_matrix",
6693
+ "type":"DT_FLOAT16,DT_FLOAT,DT_DOUBLE,DT_INT16,DT_INT32,DT_INT64,DT_INT8,DT_UINT16,DT_UINT32,DT_UINT64,DT_UINT8,DT_BOOL"
6694
+ },
6695
+ "input1":{
6696
+ "name":"dimension_limit",
6697
+ "type":"DT_INT64"
6698
+ },
6699
+ "input2":{
6700
+ "name":"maximize",
6701
+ "type":"DT_BOOL"
6702
+ },
6703
+ "opInfo":{
6704
+ "computeCost":"100",
6705
+ "engine":"DNN_VM_AICPU",
6706
+ "flagAsync":"False",
6707
+ "flagPartial":"False",
6708
+ "formatAgnostic":"False",
6709
+ "functionName":"RunCpuKernel",
6710
+ "kernelSo":"libcust_cpu_kernels.so",
6711
+ "opKernelLib":"CUSTAICPUKernel",
6712
+ "opsFlag":"OPS_FLAG_OPEN",
6713
+ "subTypeOfInferShape":"1",
6714
+ "userDefined":"True"
6715
+ },
6716
+ "output0":{
6717
+ "name":"row_ind",
6718
+ "type":"DT_INT64"
6719
+ },
6720
+ "output1":{
6721
+ "name":"col_ind",
6722
+ "type":"DT_INT64"
6723
+ }
6724
+ },
6607
6725
  "ListDiff":{
6608
6726
  "input0":{
6609
6727
  "name":"x",
Binary file
Binary file
@@ -18,7 +18,6 @@ Cifar100 convert tool for MindRecord.
18
18
 
19
19
  from importlib import import_module
20
20
  import os
21
- import numpy as np
22
21
 
23
22
  from mindspore import log as logger
24
23
  from .cifar100 import Cifar100
@@ -26,10 +25,6 @@ from ..common.exceptions import PathNotExistsError
26
25
  from ..filewriter import FileWriter
27
26
  from ..shardutils import check_filename, ExceptionThread, SUCCESS, FAILED
28
27
 
29
- try:
30
- cv_import = import_module("cv2")
31
- except ModuleNotFoundError:
32
- cv_import = None
33
28
 
34
29
  __all__ = ['Cifar100ToMR']
35
30
 
@@ -57,6 +52,8 @@ class Cifar100ToMR:
57
52
  """
58
53
 
59
54
  def __init__(self, source, destination):
55
+ self.cv_import = import_module("cv2")
56
+
60
57
  check_filename(source)
61
58
  self.source = source
62
59
 
@@ -100,12 +97,12 @@ class Cifar100ToMR:
100
97
  test_coarse_labels = cifar100_data.Test.coarse_labels
101
98
  logger.info("test images coarse label: {}".format(coarse_labels.shape))
102
99
 
103
- data_list = _construct_raw_data(images, fine_labels, coarse_labels)
104
- test_data_list = _construct_raw_data(test_images, test_fine_labels, test_coarse_labels)
100
+ data_list = self._construct_raw_data(images, fine_labels, coarse_labels)
101
+ test_data_list = self._construct_raw_data(test_images, test_fine_labels, test_coarse_labels)
105
102
 
106
- if _generate_mindrecord(self.destination, data_list, fields, "img_train") != SUCCESS:
103
+ if self._generate_mindrecord(self.destination, data_list, fields, "img_train") != SUCCESS:
107
104
  return FAILED
108
- if _generate_mindrecord(self.destination + "_test", test_data_list, fields, "img_test") != SUCCESS:
105
+ if self._generate_mindrecord(self.destination + "_test", test_data_list, fields, "img_test") != SUCCESS:
109
106
  return FAILED
110
107
  return SUCCESS
111
108
 
@@ -142,57 +139,52 @@ class Cifar100ToMR:
142
139
  raise t.exception
143
140
  return t.res
144
141
 
142
+ def _construct_raw_data(self, images, fine_labels, coarse_labels):
143
+ """
144
+ Construct raw data from cifar100 data.
145
145
 
146
- def _construct_raw_data(images, fine_labels, coarse_labels):
147
- """
148
- Construct raw data from cifar100 data.
146
+ Args:
147
+ images (list): image list from cifar100.
148
+ fine_labels (list): fine label list from cifar100.
149
+ coarse_labels (list): coarse label list from cifar100.
149
150
 
150
- Args:
151
- images (list): image list from cifar100.
152
- fine_labels (list): fine label list from cifar100.
153
- coarse_labels (list): coarse label list from cifar100.
151
+ Returns:
152
+ list[dict], data dictionary constructed from cifar100.
153
+ """
154
+ raw_data = []
155
+ for i, img in enumerate(images):
156
+ fine_label = fine_labels[i][0]
157
+ coarse_label = coarse_labels[i][0]
158
+ _, img = self.cv_import.imencode(".jpeg", img[..., [2, 1, 0]])
159
+ row_data = {"id": int(i),
160
+ "data": img.tobytes(),
161
+ "fine_label": int(fine_label),
162
+ "coarse_label": int(coarse_label)}
163
+ raw_data.append(row_data)
164
+ return raw_data
165
+
166
+ def _generate_mindrecord(self, file_name, raw_data, fields, schema_desc):
167
+ """
168
+ Generate MindRecord file from raw data.
154
169
 
155
- Returns:
156
- list[dict], data dictionary constructed from cifar100.
157
- """
158
- if not cv_import:
159
- raise ModuleNotFoundError("opencv-python module not found, please use pip install it.")
160
-
161
- raw_data = []
162
- for i, img in enumerate(images):
163
- fine_label = np.int(fine_labels[i][0])
164
- coarse_label = np.int(coarse_labels[i][0])
165
- _, img = cv_import.imencode(".jpeg", img[..., [2, 1, 0]])
166
- row_data = {"id": int(i),
167
- "data": img.tobytes(),
168
- "fine_label": int(fine_label),
169
- "coarse_label": int(coarse_label)}
170
- raw_data.append(row_data)
171
- return raw_data
172
-
173
-
174
- def _generate_mindrecord(file_name, raw_data, fields, schema_desc):
175
- """
176
- Generate MindRecord file from raw data.
170
+ Args:
171
+ file_name (str): File name of MindRecord File.
172
+ fields (list[str]): Fields would be set as index which
173
+ could not belong to blob fields and type could not be 'array' or 'bytes'.
174
+ raw_data (dict): Dict of raw data.
175
+ schema_desc (str): String of schema description.
177
176
 
178
- Args:
179
- file_name (str): File name of MindRecord File.
180
- fields (list[str]): Fields would be set as index which
181
- could not belong to blob fields and type could not be 'array' or 'bytes'.
182
- raw_data (dict): Dict of raw data.
183
- schema_desc (str): String of schema description.
184
-
185
- Returns:
186
- MSRStatus, SUCCESS or FAILED.
187
- """
188
- schema = {"id": {"type": "int64"}, "fine_label": {"type": "int64"},
189
- "coarse_label": {"type": "int64"}, "data": {"type": "bytes"}}
177
+ Returns:
178
+ MSRStatus, SUCCESS or FAILED.
179
+ """
180
+ schema = {"id": {"type": "int64"}, "fine_label": {"type": "int64"},
181
+ "coarse_label": {"type": "int64"}, "data": {"type": "bytes"}}
190
182
 
191
- logger.info("transformed MindRecord schema is: {}".format(schema))
183
+ logger.info("transformed MindRecord schema is: {}".format(schema))
192
184
 
193
- writer = FileWriter(file_name, 1)
194
- writer.add_schema(schema, schema_desc)
195
- if fields and isinstance(fields, list):
196
- writer.add_index(fields)
197
- writer.write_raw_data(raw_data)
198
- return writer.commit()
185
+ writer = FileWriter(file_name, 1)
186
+ writer.add_schema(schema, schema_desc)
187
+ if fields and isinstance(fields, list):
188
+ writer.add_index(fields)
189
+ writer.write_raw_data(raw_data)
190
+ return writer.commit()
@@ -18,7 +18,6 @@ Cifar10 convert tool for MindRecord.
18
18
 
19
19
  from importlib import import_module
20
20
  import os
21
- import numpy as np
22
21
 
23
22
  from mindspore import log as logger
24
23
  from .cifar10 import Cifar10
@@ -26,10 +25,6 @@ from ..common.exceptions import PathNotExistsError
26
25
  from ..filewriter import FileWriter
27
26
  from ..shardutils import check_filename, ExceptionThread, SUCCESS, FAILED
28
27
 
29
- try:
30
- cv_import = import_module("cv2")
31
- except ModuleNotFoundError:
32
- cv_import = None
33
28
 
34
29
  __all__ = ['Cifar10ToMR']
35
30
 
@@ -57,6 +52,8 @@ class Cifar10ToMR:
57
52
  """
58
53
 
59
54
  def __init__(self, source, destination):
55
+ self.cv_import = import_module("cv2")
56
+
60
57
  check_filename(source)
61
58
  self.source = source
62
59
 
@@ -96,12 +93,12 @@ class Cifar10ToMR:
96
93
  test_labels = cifar10_data.Test.labels
97
94
  logger.info("test images label: {}".format(test_labels.shape))
98
95
 
99
- data_list = _construct_raw_data(images, labels)
100
- test_data_list = _construct_raw_data(test_images, test_labels)
96
+ data_list = self._construct_raw_data(images, labels)
97
+ test_data_list = self._construct_raw_data(test_images, test_labels)
101
98
 
102
- if _generate_mindrecord(self.destination, data_list, fields, "img_train") != SUCCESS:
99
+ if self._generate_mindrecord(self.destination, data_list, fields, "img_train") != SUCCESS:
103
100
  return FAILED
104
- if _generate_mindrecord(self.destination + "_test", test_data_list, fields, "img_test") != SUCCESS:
101
+ if self._generate_mindrecord(self.destination + "_test", test_data_list, fields, "img_test") != SUCCESS:
105
102
  return FAILED
106
103
  return SUCCESS
107
104
 
@@ -137,56 +134,50 @@ class Cifar10ToMR:
137
134
  raise t.exception
138
135
  return t.res
139
136
 
137
+ def _construct_raw_data(self, images, labels):
138
+ """
139
+ Construct raw data from cifar10 data.
140
140
 
141
- def _construct_raw_data(images, labels):
142
- """
143
- Construct raw data from cifar10 data.
144
-
145
- Args:
146
- images (list): image list from cifar10.
147
- labels (list): label list from cifar10.
148
-
149
- Returns:
150
- list[dict], data dictionary constructed from cifar10.
151
- """
152
-
153
- if not cv_import:
154
- raise ModuleNotFoundError("opencv-python module not found, please use pip install it.")
155
-
156
- raw_data = []
157
- for i, img in enumerate(images):
158
- label = np.int(labels[i][0])
159
- _, img = cv_import.imencode(".jpeg", img[..., [2, 1, 0]])
160
- row_data = {"id": int(i),
161
- "data": img.tobytes(),
162
- "label": int(label)}
163
- raw_data.append(row_data)
164
- return raw_data
141
+ Args:
142
+ images (list): image list from cifar10.
143
+ labels (list): label list from cifar10.
165
144
 
145
+ Returns:
146
+ list[dict], data dictionary constructed from cifar10.
147
+ """
148
+ raw_data = []
149
+ for i, img in enumerate(images):
150
+ label = labels[i][0]
151
+ _, img = self.cv_import.imencode(".jpeg", img[..., [2, 1, 0]])
152
+ row_data = {"id": int(i),
153
+ "data": img.tobytes(),
154
+ "label": int(label)}
155
+ raw_data.append(row_data)
156
+ return raw_data
157
+
158
+ def _generate_mindrecord(self, file_name, raw_data, fields, schema_desc):
159
+ """
160
+ Generate MindRecord file from raw data.
166
161
 
167
- def _generate_mindrecord(file_name, raw_data, fields, schema_desc):
168
- """
169
- Generate MindRecord file from raw data.
162
+ Args:
163
+ file_name (str): File name of MindRecord File.
164
+ fields (list[str]): Fields would be set as index which
165
+ could not belong to blob fields and type could not be 'array' or 'bytes'.
166
+ raw_data (dict): dict of raw data.
167
+ schema_desc (str): String of schema description.
170
168
 
171
- Args:
172
- file_name (str): File name of MindRecord File.
173
- fields (list[str]): Fields would be set as index which
174
- could not belong to blob fields and type could not be 'array' or 'bytes'.
175
- raw_data (dict): dict of raw data.
176
- schema_desc (str): String of schema description.
177
-
178
- Returns:
179
- MSRStatus, SUCCESS or FAILED.
180
- """
169
+ Returns:
170
+ MSRStatus, SUCCESS or FAILED.
171
+ """
181
172
 
182
- schema = {"id": {"type": "int64"}, "label": {"type": "int64"},
183
- "data": {"type": "bytes"}}
173
+ schema = {"id": {"type": "int64"}, "label": {"type": "int64"},
174
+ "data": {"type": "bytes"}}
184
175
 
185
- logger.info("transformed MindRecord schema is: {}".format(schema))
176
+ logger.info("transformed MindRecord schema is: {}".format(schema))
186
177
 
187
- writer = FileWriter(file_name, 1)
188
- writer.add_schema(schema, schema_desc)
189
- if fields and isinstance(fields, list):
190
- writer.add_index(fields)
191
- writer.write_raw_data(raw_data)
192
- return writer.commit()
178
+ writer = FileWriter(file_name, 1)
179
+ writer.add_schema(schema, schema_desc)
180
+ if fields and isinstance(fields, list):
181
+ writer.add_index(fields)
182
+ writer.write_raw_data(raw_data)
183
+ return writer.commit()
@@ -22,10 +22,6 @@ from mindspore import log as logger
22
22
  from ..filewriter import FileWriter
23
23
  from ..shardutils import check_filename, ExceptionThread
24
24
 
25
- try:
26
- pd = import_module("pandas")
27
- except ModuleNotFoundError:
28
- pd = None
29
25
 
30
26
  __all__ = ['CsvToMR']
31
27
 
@@ -55,8 +51,7 @@ class CsvToMR:
55
51
  """
56
52
 
57
53
  def __init__(self, source, destination, columns_list=None, partition_number=1):
58
- if not pd:
59
- raise Exception("Module pandas is not found, please use pip install it.")
54
+ self.pd = import_module("pandas")
60
55
  if isinstance(source, str):
61
56
  check_filename(source)
62
57
  self.source = source
@@ -135,8 +130,8 @@ class CsvToMR:
135
130
  if not os.path.exists(self.source):
136
131
  raise IOError("Csv file {} do not exist.".format(self.source))
137
132
 
138
- pd.set_option('display.max_columns', None)
139
- df = pd.read_csv(self.source)
133
+ self.pd.set_option('display.max_columns', None)
134
+ df = self.pd.read_csv(self.source)
140
135
 
141
136
  csv_schema = self._get_schema(df)
142
137
 
@@ -25,10 +25,6 @@ from mindspore import log as logger
25
25
  from ..filewriter import FileWriter
26
26
  from ..shardutils import check_filename, ExceptionThread, SUCCESS, FAILED
27
27
 
28
- try:
29
- cv_import = import_module("cv2")
30
- except ModuleNotFoundError:
31
- cv_import = None
32
28
 
33
29
  __all__ = ['MnistToMR']
34
30
 
@@ -58,6 +54,8 @@ class MnistToMR:
58
54
  """
59
55
 
60
56
  def __init__(self, source, destination, partition_number=1):
57
+ self.cv_import = import_module("cv2")
58
+
61
59
  self.image_size = 28
62
60
  self.num_channels = 1
63
61
 
@@ -89,9 +87,6 @@ class MnistToMR:
89
87
 
90
88
  # pylint: disable=missing-docstring
91
89
  def run(self):
92
- if not cv_import:
93
- raise ModuleNotFoundError("opencv-python module not found, please use pip install it.")
94
-
95
90
  if self._transform_train() == FAILED:
96
91
  return FAILED
97
92
  if self._transform_test() == FAILED:
@@ -155,7 +150,7 @@ class MnistToMR:
155
150
  train_data = self._extract_images(self.train_data_filename_)
156
151
  train_labels = self._extract_labels(self.train_labels_filename_)
157
152
  for data, label in zip(train_data, train_labels):
158
- _, img = cv_import.imencode(".jpeg", data)
153
+ _, img = self.cv_import.imencode(".jpeg", data)
159
154
  yield {"label": int(label), "data": img.tobytes()}
160
155
 
161
156
  def _mnist_test_iterator(self):
@@ -168,7 +163,7 @@ class MnistToMR:
168
163
  test_data = self._extract_images(self.test_data_filename_)
169
164
  test_labels = self._extract_labels(self.test_labels_filename_)
170
165
  for data, label in zip(test_data, test_labels):
171
- _, img = cv_import.imencode(".jpeg", data)
166
+ _, img = self.cv_import.imencode(".jpeg", data)
172
167
  yield {"label": int(label), "data": img.tobytes()}
173
168
 
174
169
  def _transform_train(self):
@@ -97,10 +97,7 @@ class TFRecordToMR:
97
97
  """
98
98
 
99
99
  def __init__(self, source, destination, feature_dict, bytes_fields=None):
100
- try:
101
- self.tf = import_module("tensorflow") # just used to convert tfrecord to mindrecord
102
- except ModuleNotFoundError:
103
- raise Exception("Module tensorflow is not found, please use pip install it.")
100
+ self.tf = import_module("tensorflow") # just used to convert tfrecord to mindrecord
104
101
 
105
102
  if self.tf.__version__ < SupportedTensorFlowVersion:
106
103
  raise Exception("Module tensorflow version must be greater or equal {}.".format(SupportedTensorFlowVersion))
@@ -782,7 +782,7 @@ class Tanhshrink(Cell):
782
782
  ``Ascend`` ``GPU`` ``CPU``
783
783
 
784
784
  Examples:
785
- >>> import mindspore
785
+ >>> import mindspore as ms
786
786
  >>> from mindspore import Tensor, nn
787
787
  >>> import numpy as np
788
788
  >>> x = Tensor(np.array([1, 2, 3, 2, 1]), ms.float16)
@@ -522,12 +522,12 @@ class MultiFieldEmbeddingLookup(EmbeddingLookup):
522
522
  this interface. Type is Int32, Int64.
523
523
  - **input_values** (Tensor) - The shape of tensor is :math:`(batch\_size, seq\_length)`.
524
524
  Specifies the weights of elements of the input_indices. The lookout vector will multiply with
525
- the input_values. Type is Float32.
525
+ the input_values. Type is float32.
526
526
  - **field_ids** (Tensor) - The shape of tensor is :math:`(batch\_size, seq\_length)`.
527
527
  Specifies the field id of elements of the input_indices. Type is Int32.
528
528
 
529
529
  Outputs:
530
- Tensor, the shape of tensor is :math:`(batch\_size, field\_size, embedding\_size)`. Type is Float32.
530
+ Tensor, the shape of tensor is :math:`(batch\_size, field\_size, embedding\_size)`. Type is float32.
531
531
 
532
532
  Raises:
533
533
  TypeError: If `vocab_size` or `embedding_size` or `field_size` is not an int.