diff --git a/mindspore/ccsrc/dataset/core/tensor_row.h b/mindspore/ccsrc/dataset/core/tensor_row.h index 22fbb38c9bdfc9ab97992b4f37e6a46e28733083..49bc61657c4b050cc37a15ea8fe51d44e4138460 100644 --- a/mindspore/ccsrc/dataset/core/tensor_row.h +++ b/mindspore/ccsrc/dataset/core/tensor_row.h @@ -35,13 +35,13 @@ class TensorRow { static constexpr row_id_type kDefaultRowId = -1; // Default row id // Type definitions - typedef dsize_t size_type; - typedef std::shared_ptr value_type; - typedef std::shared_ptr &reference; - typedef const std::shared_ptr &const_reference; - typedef std::vector> vector_type; - typedef std::vector>::iterator iterator; - typedef std::vector>::const_iterator const_iterator; + using size_type = dsize_t; + using value_type = std::shared_ptr; + using reference = std::shared_ptr &; + using const_reference = const std::shared_ptr &; + using vector_type = std::vector>; + using iterator = std::vector>::iterator; + using const_iterator = std::vector>::const_iterator; TensorRow() noexcept; diff --git a/mindspore/ccsrc/dataset/engine/dataset_iterator.cc b/mindspore/ccsrc/dataset/engine/dataset_iterator.cc index 3d50d25590a5a879c79b6c421d152f5f9fc33d53..7eb38785aa96bbb1c01f763a00bbbc8ec2c914d6 100644 --- a/mindspore/ccsrc/dataset/engine/dataset_iterator.cc +++ b/mindspore/ccsrc/dataset/engine/dataset_iterator.cc @@ -84,7 +84,12 @@ Status IteratorBase::FetchNextTensorRow(TensorRow *out_row) { // Constructor of the DatasetIterator DatasetIterator::DatasetIterator(std::shared_ptr exe_tree) - : IteratorBase(), root_(exe_tree->root()), tracing_(nullptr), cur_batch_num_(0), cur_connector_size_(0) { + : IteratorBase(), + root_(exe_tree->root()), + tracing_(nullptr), + cur_batch_num_(0), + cur_connector_size_(0), + cur_connector_capacity_(0) { std::shared_ptr node; Status s = exe_tree->GetProfilingManager()->GetTracingNode(kDatasetIteratorTracingName, &node); if (s.IsOk()) { diff --git a/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.cc index 1f7edf5af5763c59b05db717b614b2a42a759026..def2ea0fee4af62070bc867212fbd7d514fb3ad2 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.cc @@ -237,6 +237,5 @@ Status BucketBatchByLengthOp::Reset() { return Status::OK(); } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.h b/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.h index 64ed523d59c5460f2faf4794ea2f812e61c5cab5..9a9025f2375ad0788ba4f248d3dfc383232be7bb 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.h +++ b/mindspore/ccsrc/dataset/engine/datasetops/bucket_batch_by_length_op.h @@ -146,7 +146,6 @@ class BucketBatchByLengthOp : public PipelineOp { std::unique_ptr child_iterator_; std::vector> buckets_; }; - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/dataset/engine/datasetops/build_vocab_op.h b/mindspore/ccsrc/dataset/engine/datasetops/build_vocab_op.h index 2ebc5a49c88e47566626eaa904335b12e8f82728..17d7bc32414dcb7a1d26a7c08d06d4af94fd4839 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/build_vocab_op.h +++ b/mindspore/ccsrc/dataset/engine/datasetops/build_vocab_op.h @@ -112,6 +112,8 @@ class BuildVocabOp : public ParallelOp { BuildVocabOp(std::shared_ptr vocab, std::vector col_names, std::pair freq_range, int64_t top_k, int32_t num_workers, int32_t op_connector_size); + ~BuildVocabOp() = default; + Status WorkerEntry(int32_t worker_id) override; // collect the work product from each worker diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.cc index efe2d8d061307279db085eeac80ee4a4d563a225..b2f85c9ba6ad107c595ebdb6bd6ce6e008ce1cfa 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - ClueOp::Builder::Builder() : builder_device_id_(0), builder_num_devices_(1), builder_num_samples_(0), builder_shuffle_files_(false) { std::shared_ptr config_manager = GlobalContext::config_manager(); @@ -545,6 +544,5 @@ Status ClueOp::CountAllFileRows(const std::vector &files, int64_t * } return Status::OK(); } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.h b/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.h index 1b8f23c97bea6c6a0c0841393cccf2809e92d304..500bbd2a34161a479ec5aecb7f25d1dfa6ea7b6e 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.h +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/clue_op.h @@ -264,7 +264,6 @@ class ClueOp : public ParallelOp { bool load_jagged_connector_; ColKeyMap cols_to_keyword_; }; - } // namespace dataset } // namespace mindspore #endif // DATASET_ENGINE_DATASETOPS_SOURCE_CLUE_OP_H_ diff --git a/mindspore/ccsrc/dataset/engine/datasetops/source/coco_op.cc b/mindspore/ccsrc/dataset/engine/datasetops/source/coco_op.cc index 60de85f9c2ebb6b5ec11e22273315959aef5864a..8d352bbd6c54501dc61befb7866bf0103c5a33a1 100644 --- a/mindspore/ccsrc/dataset/engine/datasetops/source/coco_op.cc +++ b/mindspore/ccsrc/dataset/engine/datasetops/source/coco_op.cc @@ -59,8 +59,8 @@ CocoOp::Builder::Builder() : builder_decode_(false), builder_sampler_(nullptr) { Status CocoOp::Builder::Build(std::shared_ptr *ptr) { RETURN_IF_NOT_OK(SanityCheck()); if (builder_sampler_ == nullptr) { - int64_t num_samples = 0; - int64_t start_index = 0; + const int64_t num_samples = 0; + const int64_t start_index = 0; builder_sampler_ = std::make_shared(start_index, num_samples); } builder_schema_ = std::make_unique(); diff --git a/mindspore/ccsrc/dataset/engine/perf/connector_size.h b/mindspore/ccsrc/dataset/engine/perf/connector_size.h index 910b349bf6472b2a502da2e73fbb12dc55a775e9..321972d28c92b66a0a81ede98307ec9ebe8404f2 100644 --- a/mindspore/ccsrc/dataset/engine/perf/connector_size.h +++ b/mindspore/ccsrc/dataset/engine/perf/connector_size.h @@ -44,6 +44,8 @@ class ConnectorSize : public Sampling { public: explicit ConnectorSize(ExecutionTree *tree) : tree_(tree) {} + ~ConnectorSize() = default; + // Driver function for connector size sampling. // This function samples the connector size of every nodes within the ExecutionTree Status Sample() override; @@ -54,7 +56,7 @@ class ConnectorSize : public Sampling { // @return Status - The error code return Status SaveToFile() override; - Status Init(const std::string &dir_path, const std::string &device_id); + Status Init(const std::string &dir_path, const std::string &device_id) override; // Parse op infomation and transform to json format json ParseOpInfo(const DatasetOp &node, const std::vector &size); diff --git a/mindspore/ccsrc/dataset/engine/perf/dataset_iterator_tracing.h b/mindspore/ccsrc/dataset/engine/perf/dataset_iterator_tracing.h index 4967d3a747cc29b25c590335604acedd1dc2882a..00264939fc1f98544843db0f45e02834777daede 100644 --- a/mindspore/ccsrc/dataset/engine/perf/dataset_iterator_tracing.h +++ b/mindspore/ccsrc/dataset/engine/perf/dataset_iterator_tracing.h @@ -28,7 +28,7 @@ class DatasetIteratorTracing : public Tracing { DatasetIteratorTracing() = default; // Destructor - ~DatasetIteratorTracing() = default; + ~DatasetIteratorTracing() override = default; // Record tracing data // @return Status - The error code return @@ -40,7 +40,7 @@ class DatasetIteratorTracing : public Tracing { // @return Status - The error code return Status SaveToFile() override; - Status Init(const std::string &dir_path, const std::string &device_id); + Status Init(const std::string &dir_path, const std::string &device_id) override; private: std::vector value_; diff --git a/mindspore/ccsrc/dataset/engine/perf/device_queue_tracing.h b/mindspore/ccsrc/dataset/engine/perf/device_queue_tracing.h index 54638b6f429906c11e3137870bdc374ec568b26a..f7c6da3a04cf9448f8a284b538777588617a46b2 100644 --- a/mindspore/ccsrc/dataset/engine/perf/device_queue_tracing.h +++ b/mindspore/ccsrc/dataset/engine/perf/device_queue_tracing.h @@ -29,7 +29,7 @@ class DeviceQueueTracing : public Tracing { DeviceQueueTracing() = default; // Destructor - ~DeviceQueueTracing() = default; + ~DeviceQueueTracing() override = default; // Record tracing data // @return Status - The error code return @@ -41,7 +41,7 @@ class DeviceQueueTracing : public Tracing { // @return Status - The error code return Status SaveToFile() override; - Status Init(const std::string &dir_path, const std::string &device_id); + Status Init(const std::string &dir_path, const std::string &device_id) override; private: std::vector value_; diff --git a/mindspore/ccsrc/dataset/engine/perf/monitor.cc b/mindspore/ccsrc/dataset/engine/perf/monitor.cc index 704a0e8c96ced582d71bd02183c00635cb00c0b8..9064604075b938c106cb84a260b853328da1f199 100644 --- a/mindspore/ccsrc/dataset/engine/perf/monitor.cc +++ b/mindspore/ccsrc/dataset/engine/perf/monitor.cc @@ -25,6 +25,7 @@ namespace dataset { Monitor::Monitor(ExecutionTree *tree) : tree_(tree) { std::shared_ptr cfg = GlobalContext::config_manager(); sampling_interval_ = cfg->monitor_sampling_interval(); + max_samples_ = 0; } Status Monitor::operator()() { diff --git a/mindspore/ccsrc/dataset/engine/perf/monitor.h b/mindspore/ccsrc/dataset/engine/perf/monitor.h index de6615f7cdb020eb6c81180876b1bbd3b1d8e4cc..11b3149ede147eaa5d545561ef7e3305c94bd427 100644 --- a/mindspore/ccsrc/dataset/engine/perf/monitor.h +++ b/mindspore/ccsrc/dataset/engine/perf/monitor.h @@ -33,6 +33,8 @@ class Monitor { Monitor() = default; + ~Monitor() = default; + // Functor for Perf Monitor main loop. // This function will be the entry point of Mindspore::Dataset::Task Status operator()(); diff --git a/mindspore/ccsrc/dataset/engine/perf/profiling.h b/mindspore/ccsrc/dataset/engine/perf/profiling.h index 787ea688ba7206c6ec8ff2770d63c871538072f0..d0ea91d5665a56835e1bd76b8b4cd348fa9b2764 100644 --- a/mindspore/ccsrc/dataset/engine/perf/profiling.h +++ b/mindspore/ccsrc/dataset/engine/perf/profiling.h @@ -99,7 +99,7 @@ class ProfilingManager { // If profiling is enabled. bool IsProfilingEnable() const; - std::unordered_map> &GetSamplingNodes() { return sampling_nodes_; } + const std::unordered_map> &GetSamplingNodes() { return sampling_nodes_; } private: std::unordered_map> tracing_nodes_; diff --git a/mindspore/ccsrc/dataset/engine/tdt/tdt_plugin.cc b/mindspore/ccsrc/dataset/engine/tdt/tdt_plugin.cc index d1d2779b783a1c502cfb41c4e4ce8703e57c8b2d..ca9f2176f5679b3fa8ae2da2d72a4fce6ef1c1a3 100644 --- a/mindspore/ccsrc/dataset/engine/tdt/tdt_plugin.cc +++ b/mindspore/ccsrc/dataset/engine/tdt/tdt_plugin.cc @@ -119,7 +119,8 @@ TdtStatus TdtPlugin::translate(const TensorRow &ts_row, std::vector &i data_item.tensorShape_ = dataShapes; data_item.tensorType_ = datatype; data_item.dataLen_ = ts->SizeInBytes(); - data_item.dataPtr_ = std::shared_ptr(reinterpret_cast(&(*ts->begin())), [](void *elem) {}); + data_item.dataPtr_ = + std::shared_ptr(reinterpret_cast(&(*ts->begin())), [](const void *elem) {}); items.emplace_back(data_item); MS_LOG(DEBUG) << "TDT data type is " << datatype << ", data shape is " << dataShapes << ", data length is " << ts->Size() << "."; diff --git a/mindspore/ccsrc/dataset/kernels/data/fill_op.cc b/mindspore/ccsrc/dataset/kernels/data/fill_op.cc index b0a9a370fb98aaf015888c1e911367aaa1c1d85d..63895d3a956032e09398720107a71084ed5b1450 100644 --- a/mindspore/ccsrc/dataset/kernels/data/fill_op.cc +++ b/mindspore/ccsrc/dataset/kernels/data/fill_op.cc @@ -21,7 +21,6 @@ namespace mindspore { namespace dataset { - Status FillOp::Compute(const std::shared_ptr &input, std::shared_ptr *output) { IO_CHECK(input, output); Status s = Fill(input, output, fill_value_); diff --git a/mindspore/ccsrc/dataset/kernels/data/fill_op.h b/mindspore/ccsrc/dataset/kernels/data/fill_op.h index b5333b2367be1a967c6f537f476c071fe6812134..03f59f3e67a643dab5fd84155a691cde191b1ef6 100644 --- a/mindspore/ccsrc/dataset/kernels/data/fill_op.h +++ b/mindspore/ccsrc/dataset/kernels/data/fill_op.h @@ -26,7 +26,6 @@ namespace mindspore { namespace dataset { - class FillOp : public TensorOp { public: explicit FillOp(std::shared_ptr value) : fill_value_(value) {} @@ -39,9 +38,7 @@ class FillOp : public TensorOp { private: std::shared_ptr fill_value_; }; - } // namespace dataset - } // namespace mindspore #endif // MINDSPORE_FILL_OP_H diff --git a/mindspore/ccsrc/mindrecord/meta/shard_column.cc b/mindspore/ccsrc/mindrecord/meta/shard_column.cc index b0cd6b631a580ea647c5c298b02237de784fb44e..8a2fd47bf6a83a4c35c4f933727a2078b208cf50 100644 --- a/mindspore/ccsrc/mindrecord/meta/shard_column.cc +++ b/mindspore/ccsrc/mindrecord/meta/shard_column.cc @@ -351,7 +351,7 @@ vector ShardColumn::CompressInt(const vector &src_bytes, const // Write this int to destination blob uint64_t u_n = *reinterpret_cast(&i_n); auto temp_bytes = UIntToBytesLittle(u_n, dst_int_type); - for (uint64_t j = 0; j < (kUnsignedOne << dst_int_type); j++) { + for (uint64_t j = 0; j < (kUnsignedOne << static_cast(dst_int_type)); j++) { dst_bytes[i_dst++] = temp_bytes[j]; } @@ -406,7 +406,10 @@ MSRStatus ShardColumn::UncompressInt(const uint64_t &column_id, std::unique_ptr< auto data = reinterpret_cast(array_data.get()); *data_ptr = std::make_unique(*num_bytes); - memcpy_s(data_ptr->get(), *num_bytes, data, *num_bytes); + int ret_code = memcpy_s(data_ptr->get(), *num_bytes, data, *num_bytes); + if (ret_code != 0) { + MS_LOG(ERROR) << "Failed to copy data!"; + } return SUCCESS; } @@ -444,7 +447,8 @@ int64_t ShardColumn::BytesLittleToMinIntType(const std::vector &bytes_a const IntegerType &src_i_type, IntegerType *dst_i_type) { uint64_t u_temp = 0; for (uint64_t i = 0; i < (kUnsignedOne << static_cast(src_i_type)); i++) { - u_temp = (u_temp << kBitsOfByte) + bytes_array[pos + (kUnsignedOne << src_i_type) - kUnsignedOne - i]; + u_temp = (u_temp << kBitsOfByte) + + bytes_array[pos + (kUnsignedOne << static_cast(src_i_type)) - kUnsignedOne - i]; } int64_t i_out; diff --git a/mindspore/dataset/transforms/vision/py_transforms_util.py b/mindspore/dataset/transforms/vision/py_transforms_util.py index 7a1878a04ffb3371475a871cd787afd80c86be28..d076109ff469284daa48c97477d8a865c9a96ac9 100644 --- a/mindspore/dataset/transforms/vision/py_transforms_util.py +++ b/mindspore/dataset/transforms/vision/py_transforms_util.py @@ -554,26 +554,28 @@ def adjust_hue(img, hue_factor): Returns: img (PIL Image), Hue adjusted image. """ - if not -0.5 <= hue_factor <= 0.5: - raise ValueError('hue_factor {} is not in [-0.5, 0.5].'.format(hue_factor)) + image = img + image_hue_factor = hue_factor + if not -0.5 <= image_hue_factor <= 0.5: + raise ValueError('image_hue_factor {} is not in [-0.5, 0.5].'.format(image_hue_factor)) - if not is_pil(img): - raise TypeError(augment_error_message.format(type(img))) + if not is_pil(image): + raise TypeError(augment_error_message.format(type(image))) - input_mode = img.mode - if input_mode in {'L', '1', 'I', 'F'}: - return img + mode = image.mode + if mode in {'L', '1', 'I', 'F'}: + return image - h, s, v = img.convert('HSV').split() + hue, saturation, value = img.convert('HSV').split() - np_h = np.array(h, dtype=np.uint8) + np_hue = np.array(hue, dtype=np.uint8) with np.errstate(over='ignore'): - np_h += np.uint8(hue_factor * 255) - h = Image.fromarray(np_h, 'L') + np_hue += np.uint8(image_hue_factor * 255) + hue = Image.fromarray(np_hue, 'L') - img = Image.merge('HSV', (h, s, v)).convert(input_mode) - return img + image = Image.merge('HSV', (hue, saturation, value)).convert(mode) + return image def to_type(img, output_type): diff --git a/tests/ut/python/dataset/prep_data.py b/tests/ut/python/dataset/prep_data.py deleted file mode 100644 index 46e656c29d0f9dbc2c83b9062a9b8fec0e9fbb9b..0000000000000000000000000000000000000000 --- a/tests/ut/python/dataset/prep_data.py +++ /dev/null @@ -1,124 +0,0 @@ -# Copyright 2020 Huawei Technologies Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# import jsbeautifier - -import os -import urllib -import urllib.request - - -def create_data_cache_dir(): - cwd = os.getcwd() - target_directory = os.path.join(cwd, "data_cache") - try: - if not os.path.exists(target_directory): - os.mkdir(target_directory) - except OSError: - print("Creation of the directory %s failed" % target_directory) - return target_directory - - -def download_and_uncompress(files, source_url, target_directory, is_tar=False): - for f in files: - url = source_url + f - target_file = os.path.join(target_directory, f) - - ##check if file already downloaded - if not (os.path.exists(target_file) or os.path.exists(target_file[:-3])): - urllib.request.urlretrieve(url, target_file) - if is_tar: - print("extracting from local tar file " + target_file) - rc = os.system("tar -C " + target_directory + " -xvf " + target_file) - else: - print("unzipping " + target_file) - rc = os.system("gunzip -f " + target_file) - if rc != 0: - print("Failed to uncompress ", target_file, " removing") - os.system("rm " + target_file) - ##exit with error so that build script will fail - raise SystemError - else: - print("Using cached dataset at ", target_file) - - -def download_mnist(target_directory=None): - if target_directory is None: - target_directory = create_data_cache_dir() - - ##create mnst directory - target_directory = os.path.join(target_directory, "mnist") - try: - if not os.path.exists(target_directory): - os.mkdir(target_directory) - except OSError: - print("Creation of the directory %s failed" % target_directory) - - MNIST_URL = "http://yann.lecun.com/exdb/mnist/" - files = ['train-images-idx3-ubyte.gz', - 'train-labels-idx1-ubyte.gz', - 't10k-images-idx3-ubyte.gz', - 't10k-labels-idx1-ubyte.gz'] - download_and_uncompress(files, MNIST_URL, target_directory, is_tar=False) - - return target_directory, os.path.join(target_directory, "datasetSchema.json") - - -CIFAR_URL = "https://www.cs.toronto.edu/~kriz/" - - -def download_cifar(target_directory, files, directory_from_tar): - if target_directory is None: - target_directory = create_data_cache_dir() - - download_and_uncompress([files], CIFAR_URL, target_directory, is_tar=True) - - ##if target dir was specify move data from directory created by tar - ##and put data into target dir - if target_directory is not None: - tar_dir_full_path = os.path.join(target_directory, directory_from_tar) - all_files = os.path.join(tar_dir_full_path, "*") - cmd = "mv " + all_files + " " + target_directory - if os.path.exists(tar_dir_full_path): - print("copy files back to target_directory") - print("Executing: ", cmd) - rc1 = os.system(cmd) - rc2 = os.system("rm -r " + tar_dir_full_path) - if rc1 != 0 or rc2 != 0: - print("error when running command: ", cmd) - download_file = os.path.join(target_directory, files) - print("removing " + download_file) - os.system("rm " + download_file) - - ##exit with error so that build script will fail - raise SystemError - - ##change target directory to directory after tar - return os.path.join(target_directory, directory_from_tar) - - -def download_cifar10(target_directory=None): - return download_cifar(target_directory, "cifar-10-binary.tar.gz", "cifar-10-batches-bin") - - -def download_cifar100(target_directory=None): - return download_cifar(target_directory, "cifar-100-binary.tar.gz", "cifar-100-binary") - - -def download_all_for_test(cwd): - download_mnist(os.path.join(cwd, "testMnistData")) - - -##Download all datasets to existing test directories -if __name__ == "__main__": - download_all_for_test(os.getcwd())