From: @tina_mengting_zhang Reviewed-by: Signed-off-by:tags/v1.2.0-rc1
| @@ -104,7 +104,13 @@ Status MapNode::ValidateParams() { | |||
| RETURN_STATUS_SYNTAX_ERROR(err_msg); | |||
| } | |||
| for (const auto &op : operations_) { | |||
| RETURN_IF_NOT_OK(op->ValidateParams()); | |||
| if (op == nullptr) { | |||
| std::string err_msg = "MapNode: operation must not be nullptr."; | |||
| MS_LOG(ERROR) << err_msg; | |||
| RETURN_STATUS_SYNTAX_ERROR(err_msg); | |||
| } else { | |||
| RETURN_IF_NOT_OK(op->ValidateParams()); | |||
| } | |||
| } | |||
| if (!input_columns_.empty()) { | |||
| RETURN_IF_NOT_OK(ValidateDatasetColumnParam("MapNode", "input_columns", input_columns_)); | |||
| @@ -297,8 +297,8 @@ class Dataset : public std::enable_shared_from_this<Dataset> { | |||
| /// \brief Function to create a MapDataset | |||
| /// \notes Applies each operation in operations to this dataset | |||
| /// \param[in] operations Vector of operations to be applied on the dataset. Operations are | |||
| /// applied in the order they appear in this list | |||
| /// \param[in] operations Vector of raw pointers to TensorTransform objects to be applied on the dataset. Operations | |||
| /// are applied in the order they appear in this list | |||
| /// \param[in] input_columns Vector of the names of the columns that will be passed to the first | |||
| /// operation as input. The size of this list must match the number of | |||
| /// input columns expected by the first operator. The default input_columns | |||
| @@ -326,6 +326,22 @@ class Dataset : public std::enable_shared_from_this<Dataset> { | |||
| callbacks); | |||
| } | |||
| /// \brief Function to create a MapDataset | |||
| /// \notes Applies each operation in operations to this dataset | |||
| /// \param[in] operations Vector of shared pointers to TensorTransform objects to be applied on the dataset. | |||
| /// Operations are applied in the order they appear in this list | |||
| /// \param[in] input_columns Vector of the names of the columns that will be passed to the first | |||
| /// operation as input. The size of this list must match the number of | |||
| /// input columns expected by the first operator. The default input_columns | |||
| /// is the first column | |||
| /// \param[in] output_columns Vector of names assigned to the columns outputted by the last operation | |||
| /// This parameter is mandatory if len(input_columns) != len(output_columns) | |||
| /// The size of this list must match the number of output columns of the | |||
| /// last operation. The default output_columns will have the same | |||
| /// name as the input columns, i.e., the columns will be replaced | |||
| /// \param[in] project_columns A list of column names to project | |||
| /// \param[in] cache Tensor cache to use. (default=nullptr which means no cache is used). | |||
| /// \return Shared pointer to the current MapDataset | |||
| std::shared_ptr<MapDataset> Map(std::vector<std::shared_ptr<TensorTransform>> operations, | |||
| const std::vector<std::string> &input_columns = {}, | |||
| const std::vector<std::string> &output_columns = {}, | |||
| @@ -342,6 +358,22 @@ class Dataset : public std::enable_shared_from_this<Dataset> { | |||
| callbacks); | |||
| } | |||
| /// \brief Function to create a MapDataset | |||
| /// \notes Applies each operation in operations to this dataset | |||
| /// \param[in] operations Vector of TensorTransform objects to be applied on the dataset. Operations are applied in | |||
| /// the order they appear in this list | |||
| /// \param[in] input_columns Vector of the names of the columns that will be passed to the first | |||
| /// operation as input. The size of this list must match the number of | |||
| /// input columns expected by the first operator. The default input_columns | |||
| /// is the first column | |||
| /// \param[in] output_columns Vector of names assigned to the columns outputted by the last operation | |||
| /// This parameter is mandatory if len(input_columns) != len(output_columns) | |||
| /// The size of this list must match the number of output columns of the | |||
| /// last operation. The default output_columns will have the same | |||
| /// name as the input columns, i.e., the columns will be replaced | |||
| /// \param[in] project_columns A list of column names to project | |||
| /// \param[in] cache Tensor cache to use. (default=nullptr which means no cache is used). | |||
| /// \return Shared pointer to the current MapDataset | |||
| std::shared_ptr<MapDataset> Map(const std::vector<std::reference_wrapper<TensorTransform>> operations, | |||
| const std::vector<std::string> &input_columns = {}, | |||
| const std::vector<std::string> &output_columns = {}, | |||
| @@ -60,6 +60,7 @@ class BasicTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~BasicTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -104,6 +105,7 @@ class BertTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~BertTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -123,6 +125,7 @@ class CaseFold : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~CaseFold() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| //// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -153,12 +156,13 @@ class JiebaTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~JiebaTokenizer() = default; | |||
| Status AddWord(const std::string &word, int64_t freq = 0); | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| Status AddWord(const std::string &word, int64_t freq = 0); | |||
| private: | |||
| struct Data; | |||
| std::shared_ptr<Data> data_; | |||
| @@ -183,6 +187,7 @@ class Lookup : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~Lookup() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -214,6 +219,7 @@ class Ngram : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~Ngram() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -242,6 +248,7 @@ class NormalizeUTF8 : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~NormalizeUTF8() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -267,6 +274,7 @@ class RegexReplace : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~RegexReplace() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -294,6 +302,7 @@ class RegexTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~RegexTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -324,6 +333,7 @@ class SentencePieceTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~SentencePieceTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -346,6 +356,7 @@ class SlidingWindow : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~SlidingWindow() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -371,6 +382,7 @@ class ToNumber : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~ToNumber() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -390,6 +402,7 @@ class TruncateSequencePair : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~TruncateSequencePair() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -409,6 +422,7 @@ class UnicodeCharTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~UnicodeCharTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -430,6 +444,7 @@ class UnicodeScriptTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~UnicodeScriptTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -449,6 +464,7 @@ class WhitespaceTokenizer : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~WhitespaceTokenizer() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -31,10 +31,32 @@ namespace dataset { | |||
| class TensorOperation; | |||
| // We need the following two groups of forward declaration to friend the class in class TensorTransform. | |||
| namespace transforms { | |||
| class Compose; | |||
| class RandomApply; | |||
| class RandomChoice; | |||
| } // namespace transforms | |||
| namespace vision { | |||
| class BoundingBoxAugment; | |||
| class RandomSelectSubpolicy; | |||
| class UniformAugment; | |||
| } // namespace vision | |||
| // Abstract class to represent a tensor transform operation in the data pipeline. | |||
| /// \class TensorTransform transforms.h | |||
| /// \brief A base class to represent a tensor transform operation in the data pipeline. | |||
| class TensorTransform : public std::enable_shared_from_this<TensorTransform> { | |||
| friend class Dataset; | |||
| friend class Execute; | |||
| friend class transforms::Compose; | |||
| friend class transforms::RandomApply; | |||
| friend class transforms::RandomChoice; | |||
| friend class vision::BoundingBoxAugment; | |||
| friend class vision::RandomSelectSubpolicy; | |||
| friend class vision::UniformAugment; | |||
| public: | |||
| /// \brief Constructor | |||
| TensorTransform() {} | |||
| @@ -42,6 +64,7 @@ class TensorTransform : public std::enable_shared_from_this<TensorTransform> { | |||
| /// \brief Destructor | |||
| ~TensorTransform() = default; | |||
| protected: | |||
| /// \brief Pure virtual function to convert a TensorTransform class into a IR TensorOperation object. | |||
| /// \return shared pointer to the newly created TensorOperation. | |||
| virtual std::shared_ptr<TensorOperation> Parse() = 0; | |||
| @@ -60,14 +83,19 @@ namespace transforms { | |||
| class Compose : public TensorTransform { | |||
| public: | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of transformations to be applied. | |||
| /// \param[in] transforms A vector of raw pointers to TensorTransform objects to be applied. | |||
| explicit Compose(const std::vector<TensorTransform *> &transforms); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of shared pointers to TensorTransform objects to be applied. | |||
| explicit Compose(const std::vector<std::shared_ptr<TensorTransform>> &transforms); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of TensorTransform objects to be applied. | |||
| explicit Compose(const std::vector<std::reference_wrapper<TensorTransform>> &transforms); | |||
| /// \brief Destructor | |||
| ~Compose() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -88,6 +116,7 @@ class Duplicate : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~Duplicate() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -104,6 +133,7 @@ class OneHot : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~OneHot() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -118,15 +148,22 @@ class OneHot : public TensorTransform { | |||
| class RandomApply : public TensorTransform { | |||
| public: | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of transformations to be applied. | |||
| /// \param[in] transforms A vector of raw pointers to TensorTransform objects to be applied. | |||
| /// \param[in] prob The probability to apply the transformation list (default=0.5) | |||
| explicit RandomApply(const std::vector<TensorTransform *> &transforms, double prob = 0.5); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of shared pointers to TensorTransform objects to be applied. | |||
| /// \param[in] prob The probability to apply the transformation list (default=0.5) | |||
| explicit RandomApply(const std::vector<std::shared_ptr<TensorTransform>> &transforms, double prob = 0.5); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of TensorTransform objects to be applied. | |||
| /// \param[in] prob The probability to apply the transformation list (default=0.5) | |||
| explicit RandomApply(const std::vector<std::reference_wrapper<TensorTransform>> &transforms, double prob = 0.5); | |||
| /// \brief Destructor | |||
| ~RandomApply() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -141,14 +178,19 @@ class RandomApply : public TensorTransform { | |||
| class RandomChoice : public TensorTransform { | |||
| public: | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of transformations to be chosen from to apply. | |||
| /// \param[in] transforms A vector of raw pointers to TensorTransform objects to be applied. | |||
| explicit RandomChoice(const std::vector<TensorTransform *> &transforms); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of shared pointers to TensorTransform objects to be applied. | |||
| explicit RandomChoice(const std::vector<std::shared_ptr<TensorTransform>> &transforms); | |||
| /// \brief Constructor. | |||
| /// \param[in] transforms A vector of TensorTransform objects to be applied. | |||
| explicit RandomChoice(const std::vector<std::reference_wrapper<TensorTransform>> &transforms); | |||
| /// \brief Destructor | |||
| ~RandomChoice() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -171,6 +213,7 @@ class TypeCast : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~TypeCast() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -191,6 +234,7 @@ class Unique : public TensorTransform { | |||
| /// \brief Destructor | |||
| ~Unique() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -48,6 +48,7 @@ class AutoContrast : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~AutoContrast() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -79,6 +80,7 @@ class BoundingBoxAugment : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~BoundingBoxAugment() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -102,6 +104,7 @@ class CutMixBatch : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~CutMixBatch() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -123,6 +126,7 @@ class CutOut : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~CutOut() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -142,6 +146,7 @@ class Equalize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Equalize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -157,6 +162,7 @@ class HWC2CHW : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~HWC2CHW() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -172,6 +178,7 @@ class Invert : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Invert() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -189,6 +196,7 @@ class MixUpBatch : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~MixUpBatch() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -219,6 +227,7 @@ class NormalizePad : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~NormalizePad() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -255,6 +264,7 @@ class Pad : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Pad() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -277,6 +287,7 @@ class RandomColor : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomColor() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -306,6 +317,7 @@ class RandomColorAdjust : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomColorAdjust() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -341,6 +353,7 @@ class RandomCrop : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomCrop() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -373,6 +386,7 @@ class RandomCropDecodeResize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomCropDecodeResize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -410,6 +424,7 @@ class RandomCropWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomCropWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -430,6 +445,7 @@ class RandomHorizontalFlip : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomHorizontalFlip() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -450,6 +466,7 @@ class RandomHorizontalFlipWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomHorizontalFlipWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -470,6 +487,7 @@ class RandomPosterize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomPosterize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -492,6 +510,7 @@ class RandomResize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomResize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -515,6 +534,7 @@ class RandomResizeWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomResizeWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -546,6 +566,7 @@ class RandomResizedCrop : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomResizedCrop() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -577,6 +598,7 @@ class RandomResizedCropWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomResizedCropWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -605,6 +627,7 @@ class RandomRotation : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomRotation() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -637,6 +660,7 @@ class RandomSelectSubpolicy : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomSelectSubpolicy() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -658,6 +682,7 @@ class RandomSharpness : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomSharpness() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -679,6 +704,7 @@ class RandomSolarize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomSolarize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -699,6 +725,7 @@ class RandomVerticalFlip : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomVerticalFlip() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -719,6 +746,7 @@ class RandomVerticalFlipWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RandomVerticalFlipWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -740,6 +768,7 @@ class Rescale : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Rescale() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -763,6 +792,7 @@ class ResizeWithBBox : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~ResizeWithBBox() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -782,6 +812,7 @@ class RGBA2BGR : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RGBA2BGR() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -797,6 +828,7 @@ class RGBA2RGB : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~RGBA2RGB() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -820,6 +852,7 @@ class SoftDvppDecodeRandomCropResizeJpeg : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~SoftDvppDecodeRandomCropResizeJpeg() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -849,6 +882,7 @@ class SoftDvppDecodeResizeJpeg : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~SoftDvppDecodeResizeJpeg() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -868,6 +902,7 @@ class SwapRedBlue : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~SwapRedBlue() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -895,6 +930,7 @@ class UniformAugment : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~UniformAugment() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -43,6 +43,7 @@ class DvppDecodeResizeJpeg : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~DvppDecodeResizeJpeg() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -64,6 +65,7 @@ class DvppDecodeResizeCropJpeg : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~DvppDecodeResizeCropJpeg() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -83,6 +85,7 @@ class DvppDecodePng : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~DvppDecodePng() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -79,6 +79,7 @@ class CenterCrop : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~CenterCrop() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -104,6 +105,7 @@ class Crop : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Crop() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -124,6 +126,7 @@ class Decode : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Decode() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -149,6 +152,7 @@ class Normalize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Normalize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -212,6 +216,7 @@ class Resize : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Resize() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -233,6 +238,7 @@ class Rotate : public TensorTransform { | |||
| /// \brief Destructor. | |||
| ~Rotate() = default; | |||
| protected: | |||
| /// \brief Function to convert TensorTransform object into a TensorOperation object. | |||
| /// \return Shared pointer to TensorOperation object. | |||
| std::shared_ptr<TensorOperation> Parse() override; | |||
| @@ -997,6 +997,25 @@ TEST_F(MindDataTestPipeline, TestMapDuplicateColumnFail) { | |||
| EXPECT_EQ(iter3, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestMapNullOperation) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMapNullOperation."; | |||
| // Create an ImageFolder Dataset | |||
| std::string folder_path = datasets_root_path_ + "/testPK/data/"; | |||
| std::shared_ptr<Dataset> ds = ImageFolder(folder_path, true, std::make_shared<RandomSampler>(false, 10)); | |||
| EXPECT_NE(ds, nullptr); | |||
| // Create a Map operation on ds | |||
| std::shared_ptr<TensorTransform> operation = nullptr; | |||
| auto ds1 = ds->Map({operation}, {"image"}, {}, {}); | |||
| EXPECT_NE(ds1, nullptr); | |||
| // Create an iterator over the result of the above dataset | |||
| std::shared_ptr<Iterator> iter1 = ds1->CreateIterator(); | |||
| // Expect failure: Operation is nullptr | |||
| EXPECT_EQ(iter1, nullptr); | |||
| } | |||
| TEST_F(MindDataTestPipeline, TestProjectMapAutoInjection) { | |||
| MS_LOG(INFO) << "Doing MindDataTestPipeline.TestProjectMapAutoInjection"; | |||
| @@ -91,8 +91,9 @@ TEST_F(MindDataTestOptimizationPass, MindDataTestTensorFusionPassPreBuiltTensorO | |||
| MS_LOG(INFO) << "Doing MindDataTestOptimizationPass-MindDataTestTensorFusionPassPreBuiltTensorOperation."; | |||
| std::string folder_path = datasets_root_path_ + "/testPK/data/"; | |||
| // make prebuilt tensor operation | |||
| auto decode = std::make_shared<transforms::PreBuiltOperation>(vision::Decode().Parse()->Build()); | |||
| auto resize = std::make_shared<transforms::PreBuiltOperation>(vision::RandomResizedCrop({100}).Parse()->Build()); | |||
| auto decode = std::make_shared<transforms::PreBuiltOperation>(vision::DecodeOperation(true).Build()); | |||
| auto resize = std::make_shared<transforms::PreBuiltOperation>( | |||
| vision::RandomResizedCropOperation({100}, {0.5}, {0.1}, InterpolationMode::kNearestNeighbour, 5).Build()); | |||
| std::vector<std::shared_ptr<TensorOperation>> op_list = {decode, resize}; | |||
| std::vector<std::string> op_name = {"image"}; | |||
| std::shared_ptr<DatasetNode> root = ImageFolder(folder_path, false)->IRNode(); | |||