!9038 port name functions from TensorOp to TensorOperation

From: @mhmotallebi
Reviewed-by: 
Signed-off-by:
pull/9038/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit a37e9710b5

@ -37,6 +37,14 @@ namespace dataset {
// Transform operations for text
namespace text {
// Char arrays storing name of corresponding classes (in alphabetical order)
constexpr char kJiebaTokenizerOperation[] = "JiebaTokenizer";
constexpr char kLookupOperation[] = "Lookup";
constexpr char kNgramOperation[] = "Ngram";
constexpr char kSentencepieceTokenizerOperation[] = "SentencepieceTokenizer";
constexpr char kSlidingWindowOperation[] = "SlidingWindow";
constexpr char kWhitespaceTokenizerOperation[] = "WhitespaceTokenizer";
// Text Op classes (in alphabetical order)
class JiebaTokenizerOperation;
class LookupOperation;
@ -128,6 +136,8 @@ class JiebaTokenizerOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kJiebaTokenizerOperation; }
private:
std::string hmm_path_;
std::string mp_path_;
@ -146,6 +156,8 @@ class LookupOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kLookupOperation; }
private:
std::shared_ptr<Vocab> vocab_;
std::string unknown_token_;
@ -164,6 +176,8 @@ class NgramOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kNgramOperation; }
private:
std::vector<int32_t> ngrams_;
std::pair<std::string, int32_t> left_pad_;
@ -183,6 +197,8 @@ class SentencePieceTokenizerOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kSentencepieceTokenizerOperation; }
private:
std::shared_ptr<SentencePieceVocab> vocab_;
std::string vocab_path_;
@ -200,6 +216,8 @@ class SlidingWindowOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kSlidingWindowOperation; }
private:
int32_t width_;
int32_t axis_;
@ -216,6 +234,8 @@ class WhitespaceTokenizerOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kWhitespaceTokenizerOperation; }
private:
bool with_offsets_;
};

@ -28,6 +28,17 @@ namespace dataset {
class TensorOp;
// Char arrays storing name of corresponding classes (in alphabetical order)
constexpr char kComposeOperation[] = "Compose";
constexpr char kDuplicateOperation[] = "Duplicate";
constexpr char kOneHotOperation[] = "OneHot";
constexpr char kPreBuiltOperation[] = "PreBuilt";
constexpr char kRandomApplyOperation[] = "RandomApply";
constexpr char kRandomChoiceOperation[] = "RandomChoice";
constexpr char kRandomSelectSubpolicyOperation[] = "RandomSelectSubpolicy";
constexpr char kTypeCastOperation[] = "TypeCast";
constexpr char kUniqueOperation[] = "Unique";
// Abstract class to represent a dataset in the data pipeline.
class TensorOperation : public std::enable_shared_from_this<TensorOperation> {
public:
@ -46,6 +57,8 @@ class TensorOperation : public std::enable_shared_from_this<TensorOperation> {
virtual Status ValidateParams() = 0;
virtual std::string Name() const = 0;
/// \brief Check whether the operation is deterministic.
/// \return true if this op is a random op (returns non-deterministic result e.g. RandomCrop)
bool IsRandomOp() const { return random_op_; }
@ -146,6 +159,8 @@ class ComposeOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kComposeOperation; }
private:
std::vector<std::shared_ptr<TensorOperation>> transforms_;
};
@ -159,6 +174,8 @@ class DuplicateOperation : public TensorOperation {
std::shared_ptr<TensorOp> Build() override;
Status ValidateParams() override;
std::string Name() const override { return kDuplicateOperation; }
};
class OneHotOperation : public TensorOperation {
@ -171,6 +188,8 @@ class OneHotOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kOneHotOperation; }
private:
float num_classes_;
};
@ -185,6 +204,8 @@ class PreBuiltOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kPreBuiltOperation; }
private:
std::shared_ptr<TensorOp> op_;
};
@ -199,6 +220,8 @@ class RandomApplyOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kRandomApplyOperation; }
private:
std::vector<std::shared_ptr<TensorOperation>> transforms_;
double prob_;
@ -214,6 +237,8 @@ class RandomChoiceOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kRandomChoiceOperation; }
private:
std::vector<std::shared_ptr<TensorOperation>> transforms_;
};
@ -227,6 +252,8 @@ class TypeCastOperation : public TensorOperation {
Status ValidateParams() override;
std::string Name() const override { return kTypeCastOperation; }
private:
std::string data_type_;
};
@ -241,6 +268,8 @@ class UniqueOperation : public TensorOperation {
std::shared_ptr<TensorOp> Build() override;
Status ValidateParams() override;
std::string Name() const override { return kUniqueOperation; }
};
#endif
} // namespace transforms

File diff suppressed because it is too large Load Diff

@ -461,6 +461,17 @@ TEST_F(MindDataTestPipeline, TestNgramFail) {
EXPECT_EQ(ngram_op4, nullptr);
}
TEST_F(MindDataTestPipeline, TestTextOperationName) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTextOperationName.";
// Create object for the tensor op, and check the name
std::string data_file = datasets_root_path_ + "/testVocab/words.txt";
std::shared_ptr<TensorOperation> sentence_piece_tokenizer_op =
text::SentencePieceTokenizer(data_file, SPieceTokenizerOutType::kString);
std::string correct_name = "SentencepieceTokenizer";
EXPECT_EQ(correct_name, sentence_piece_tokenizer_op->Name());
}
TEST_F(MindDataTestPipeline, TestWhitespaceTokenizerSuccess) {
// Testing the parameter of WhitespaceTokenizer interface when the with_offsets is default.
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestWhitespaceTokenizerSuccess.";

@ -379,6 +379,15 @@ TEST_F(MindDataTestPipeline, TestRandomChoiceFail) {
EXPECT_EQ(random_choice3, nullptr);
}
TEST_F(MindDataTestPipeline, TestTransformOperationName) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTransformOperationName.";
// Create object for the tensor op, and check the name
std::shared_ptr<TensorOperation> duplicate_op = transforms::Duplicate();
std::string correct_name = "Duplicate";
EXPECT_EQ(correct_name, duplicate_op->Name());
}
TEST_F(MindDataTestPipeline, TestTypeCastSuccess) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTypeCastSuccess.";

@ -3018,3 +3018,19 @@ TEST_F(MindDataTestPipeline, TestUniformAugWithOps) {
// Manually terminate the pipeline
iter->Stop();
}
TEST_F(MindDataTestPipeline, TestVisionOperationName) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVisionOperationName.";
std::string correct_name;
// Create object for the tensor op, and check the name
std::shared_ptr<TensorOperation> random_vertical_flip_op = vision::RandomVerticalFlip(0.5);
correct_name = "RandomVerticalFlip";
EXPECT_EQ(correct_name, random_vertical_flip_op->Name());
// Create object for the tensor op, and check the name
std::shared_ptr<TensorOperation> softDvpp_decode_resize_jpeg_op = vision::SoftDvppDecodeResizeJpeg({1, 1});
correct_name = "SoftDvppDecodeResizeJpeg";
EXPECT_EQ(correct_name, softDvpp_decode_resize_jpeg_op->Name());
}

Loading…
Cancel
Save