diff --git a/include/api/status.h b/include/api/status.h index ef91a900571..e59f16e4fea 100644 --- a/include/api/status.h +++ b/include/api/status.h @@ -141,7 +141,7 @@ class MS_API Status { private: // api without std::string - explicit Status(enum StatusCode status_code, const std::vector &status_msg); + Status(enum StatusCode status_code, const std::vector &status_msg); Status(const enum StatusCode code, int line_of_code, const char *file_name, const std::vector &extra); std::vector ToCString() const; std::vector GetErrDescriptionChar() const; diff --git a/mindspore/ccsrc/minddata/dataset/api/execute.cc b/mindspore/ccsrc/minddata/dataset/api/execute.cc index aed2e5f90a3..e1ee279dd72 100644 --- a/mindspore/ccsrc/minddata/dataset/api/execute.cc +++ b/mindspore/ccsrc/minddata/dataset/api/execute.cc @@ -454,6 +454,10 @@ std::vector AippStdFilter(const std::vector &normalize_para) { if (normalize_para.size() == 6) { // If Normalize operator exist auto zeros = std::find(std::begin(normalize_para), std::end(normalize_para), 0); if (zeros == std::end(normalize_para)) { + if (std::any_of(normalize_para.begin() + 3, normalize_para.end(), [](uint32_t i) { return i == 0; })) { + MS_LOG(ERROR) << "value in normalize para got 0."; + return {}; + } std::transform(normalize_para.begin() + 3, normalize_para.end(), std::back_inserter(aipp_std), [](uint32_t i) { return 10000 / static_cast(i); }); } else { // If 0 occurs in std vector diff --git a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc index 79620e3176a..53af77025b0 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc @@ -83,7 +83,7 @@ std::unordered_map> toIntMap(const py::dict input_di std::pair toIntPair(const py::tuple tuple) { std::pair pair; - if (!tuple.empty()) { + if (tuple.size() == 2) { pair = std::make_pair(toInt64((tuple)[0]), toInt64((tuple)[1])); } return pair; diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/dataset_node.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/dataset_node.cc index a08adbcdabb..7b904f2c27c 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/dataset_node.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/dataset_node.cc @@ -23,6 +23,7 @@ #include "minddata/dataset/engine/opt/pass.h" #include "minddata/dataset/util/random.h" +#include "minddata/dataset/util/status.h" namespace mindspore { namespace dataset { @@ -77,6 +78,8 @@ Status ValidateDatasetDirParam(const std::string &dataset_name, std::string data RETURN_STATUS_SYNTAX_ERROR(err_msg); } + std::string real_path; + RETURN_IF_NOT_OK(Path::RealPath(dataset_dir, real_path)); Path dir(dataset_dir); if (!dir.IsDirectory()) { std::string err_msg = dataset_name + ": dataset_dir: [" + dataset_dir + "] is an invalid directory path."; diff --git a/mindspore/ccsrc/minddata/dataset/include/dataset/data_helper.h b/mindspore/ccsrc/minddata/dataset/include/dataset/data_helper.h index e51195ba3b9..80aec6ba97f 100644 --- a/mindspore/ccsrc/minddata/dataset/include/dataset/data_helper.h +++ b/mindspore/ccsrc/minddata/dataset/include/dataset/data_helper.h @@ -325,6 +325,9 @@ class DataHelper { return Status(kMDUnexpectedError, "Error opening Bin file to write"); } size_t length = data.size(); + if (length == 0) { + return Status(kMDUnexpectedError, "size of data is 0 when written into file."); + } o.write(reinterpret_cast(&data[0]), std::streamsize(length * sizeof(T))); o.close(); } diff --git a/mindspore/ccsrc/minddata/dataset/include/dataset/iterator.h b/mindspore/ccsrc/minddata/dataset/include/dataset/iterator.h index 7bbb8152ac0..c707c95ccdf 100644 --- a/mindspore/ccsrc/minddata/dataset/include/dataset/iterator.h +++ b/mindspore/ccsrc/minddata/dataset/include/dataset/iterator.h @@ -64,6 +64,9 @@ class Iterator { /// \param[out] row The output tensor row. /// \return Status error code, returns OK if no error encountered. Status GetNextRow(MSTensorMap *row) { + if (row == nullptr) { + return Status(kMDUnexpectedError, "Got nullptr when GetNext row."); + } MSTensorMapChar row_; row_.clear(); row->clear(); diff --git a/mindspore/ccsrc/minddata/dataset/include/dataset/samplers.h b/mindspore/ccsrc/minddata/dataset/include/dataset/samplers.h index 710e1317247..d76aee601e8 100644 --- a/mindspore/ccsrc/minddata/dataset/include/dataset/samplers.h +++ b/mindspore/ccsrc/minddata/dataset/include/dataset/samplers.h @@ -82,8 +82,8 @@ class DistributedSampler final : public Sampler { /// \param[in] offset The starting position where access to elements in the dataset begins (default=-1). /// \param[in] even_dist If true, each shard would return the same number of rows (default=true). /// If false the total rows returned by all the shards would not have overlap. - explicit DistributedSampler(int64_t num_shards, int64_t shard_id, bool shuffle = true, int64_t num_samples = 0, - uint32_t seed = 1, int64_t offset = -1, bool even_dist = true); + DistributedSampler(int64_t num_shards, int64_t shard_id, bool shuffle = true, int64_t num_samples = 0, + uint32_t seed = 1, int64_t offset = -1, bool even_dist = true); /// \brief Destructor. ~DistributedSampler() = default;