!11245 Pushing down pipeline json serializer logic to C++ IR - PART II

From: @tina_mengting_zhang
Reviewed-by: 
Signed-off-by:
pull/11245/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 91842af2ad

@ -526,6 +526,11 @@ std::shared_ptr<TensorOp> CenterCropOperation::Build() {
return tensor_op;
}
Status CenterCropOperation::to_json(nlohmann::json *out_json) {
(*out_json)["size"] = size_;
return Status::OK();
}
// CropOperation.
CropOperation::CropOperation(std::vector<int32_t> coordinates, std::vector<int32_t> size)
: coordinates_(coordinates), size_(size) {}
@ -638,6 +643,11 @@ Status DecodeOperation::ValidateParams() { return Status::OK(); }
std::shared_ptr<TensorOp> DecodeOperation::Build() { return std::make_shared<DecodeOp>(rgb_); }
Status DecodeOperation::to_json(nlohmann::json *out_json) {
(*out_json)["rgb"] = rgb_;
return Status::OK();
}
// EqualizeOperation
Status EqualizeOperation::ValidateParams() { return Status::OK(); }
@ -801,6 +811,14 @@ std::shared_ptr<TensorOp> NormalizeOperation::Build() {
return std::make_shared<NormalizeOp>(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2]);
}
Status NormalizeOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["mean"] = mean_;
args["std"] = std_;
*out_json = args;
return Status::OK();
}
#ifndef ENABLE_ANDROID
// NormalizePadOperation
NormalizePadOperation::NormalizePadOperation(const std::vector<float> &mean, const std::vector<float> &std,
@ -893,6 +911,15 @@ std::shared_ptr<TensorOp> PadOperation::Build() {
return tensor_op;
}
Status PadOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["padding"] = padding_;
args["fill_value"] = fill_value_;
args["padding_mode"] = padding_mode_;
*out_json = args;
return Status::OK();
}
// RandomAffineOperation
RandomAffineOperation::RandomAffineOperation(const std::vector<float_t> &degrees,
const std::vector<float_t> &translate_range,
@ -1188,6 +1215,16 @@ std::shared_ptr<TensorOp> RandomColorAdjustOperation::Build() {
return tensor_op;
}
Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["brightness"] = brightness_;
args["contrast"] = contrast_;
args["saturation"] = saturation_;
args["hue"] = hue_;
*out_json = args;
return Status::OK();
}
// RandomCropOperation
RandomCropOperation::RandomCropOperation(std::vector<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
std::vector<uint8_t> fill_value, BorderType padding_mode)
@ -1261,6 +1298,17 @@ std::shared_ptr<TensorOp> RandomCropOperation::Build() {
return tensor_op;
}
Status RandomCropOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["size"] = size_;
args["padding"] = padding_;
args["pad_if_needed"] = pad_if_needed_;
args["fill_value"] = fill_value_;
args["padding_mode"] = padding_mode_;
*out_json = args;
return Status::OK();
}
// RandomCropDecodeResizeOperation
RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(std::vector<int32_t> size, std::vector<float> scale,
std::vector<float> ratio,
@ -1735,6 +1783,17 @@ std::shared_ptr<TensorOp> RandomRotationOperation::Build() {
return tensor_op;
}
Status RandomRotationOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["degrees"] = degrees_;
args["interpolation_mode"] = interpolation_mode_;
args["expand"] = expand_;
args["center"] = center_;
args["fill_value"] = fill_value_;
*out_json = args;
return Status::OK();
}
// RandomSelectSubpolicyOperation.
RandomSelectSubpolicyOperation::RandomSelectSubpolicyOperation(
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy)
@ -1889,6 +1948,14 @@ std::shared_ptr<TensorOp> RescaleOperation::Build() {
return tensor_op;
}
Status RescaleOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["rescale"] = rescale_;
args["shift"] = shift_;
*out_json = args;
return Status::OK();
}
#endif
// ResizeOperation
ResizeOperation::ResizeOperation(std::vector<int32_t> size, InterpolationMode interpolation)
@ -1920,6 +1987,14 @@ std::shared_ptr<TensorOp> ResizeOperation::Build() {
return std::make_shared<ResizeOp>(height, width, interpolation_);
}
Status ResizeOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["size"] = size_;
args["interpolation"] = interpolation_;
*out_json = args;
return Status::OK();
}
// RotateOperation
RotateOperation::RotateOperation() { rotate_op = std::make_shared<RotateOp>(0); }

@ -44,18 +44,5 @@ Status DatasetCacheImpl::CreateCacheOp(int32_t num_workers, std::shared_ptr<Data
return Status::OK();
}
Status DatasetCacheImpl::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["session_id"] = session_id_;
args["cache_memory_size"] = cache_mem_sz_;
args["spill"] = spill_;
if (hostname_) args["hostname"] = hostname_.value();
if (port_) args["port"] = port_.value();
if (num_connections_) args["num_connections"] = num_connections_.value();
if (prefetch_sz_) args["prefetch_size"] = prefetch_sz_.value();
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -60,8 +60,6 @@ class DatasetCacheImpl : public DatasetCache {
~DatasetCacheImpl() = default;
Status to_json(nlohmann::json *out_json) override;
private:
std::shared_ptr<CacheClient> cache_client_;
session_id_type session_id_;

@ -36,5 +36,15 @@ Status PreBuiltDatasetCache::CreateCacheOp(int32_t num_workers, std::shared_ptr<
return Status::OK();
}
Status PreBuiltDatasetCache::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["session_id"] = cache_client_->session_id();
args["cache_memory_size"] = cache_client_->GetCacheMemSz();
args["spill"] = cache_client_->isSpill();
args["num_connections"] = cache_client_->GetNumConnections();
args["prefetch_size"] = cache_client_->GetPrefetchSize();
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -42,6 +42,8 @@ class PreBuiltDatasetCache : public DatasetCache {
Status ValidateParams() override { return Status::OK(); }
Status to_json(nlohmann::json *out_json) override;
private:
std::shared_ptr<CacheClient> cache_client_;
};

@ -63,6 +63,15 @@ class BucketBatchByLengthNode : public DatasetNode {
bool IsSizeDefined() override { return false; };
/// \brief Getter functions
const std::vector<std::string> &ColumnNames() const { return column_names_; }
const std::vector<int32_t> &BucketBoundaries() const { return bucket_boundaries_; }
const std::vector<int32_t> &BucketBatchSizes() const { return bucket_batch_sizes_; }
const std::shared_ptr<TensorOp> &ElementLengthFunction() const { return element_length_function_; }
const std::map<std::string, std::pair<TensorShape, std::shared_ptr<Tensor>>> &PadInfo() const { return pad_info_; }
bool PadToBucketBoundary() const { return pad_to_bucket_boundary_; }
bool DropRemainder() const { return drop_remainder_; }
private:
std::vector<std::string> column_names_;
std::vector<int32_t> bucket_boundaries_;

@ -72,6 +72,14 @@ class BuildSentenceVocabNode : public DatasetNode {
/// \return Status of the node visit
Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
/// \brief Getter functions
const std::shared_ptr<SentencePieceVocab> &GetVocab() const { return vocab_; }
const std::vector<std::string> &ColNames() const { return col_names_; }
int32_t VocabSize() const { return vocab_size_; }
float CharacterCoverage() const { return character_coverage_; }
SentencePieceModel ModelType() const { return model_type_; }
const std::unordered_map<std::string, std::string> &Params() const { return params_; }
private:
std::shared_ptr<SentencePieceVocab> vocab_;
std::vector<std::string> col_names_;

@ -70,6 +70,14 @@ class BuildVocabNode : public DatasetNode {
/// \return Status of the node visit
Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
/// \brief Getter functions
const std::shared_ptr<Vocab> &GetVocab() const { return vocab_; }
const std::vector<std::string> &Columns() const { return columns_; }
const std::pair<int64_t, int64_t> &FreqRange() const { return freq_range_; }
int64_t TopK() const { return top_k_; }
const std::vector<std::string> &SpecialTokens() const { return special_tokens_; }
bool SpecialFirst() const { return special_first_; }
private:
std::shared_ptr<Vocab> vocab_;
std::vector<std::string> columns_;

@ -61,6 +61,10 @@ class ConcatNode : public DatasetNode {
bool IsSizeDefined() override { return false; }
/// \brief Getter functions
const std::vector<std::pair<int, int>> &ChildrenFlagAndNums() const { return children_flag_and_nums_; }
const std::vector<std::pair<int, int>> &ChildrenStartEndIndex() const { return children_start_end_index_; }
private:
std::shared_ptr<SamplerObj> sampler_;
std::vector<std::pair<int, int>> children_flag_and_nums_;

@ -73,5 +73,13 @@ Status FilterNode::AcceptAfter(IRNodePass *const p, bool *const modified) {
return p->VisitAfter(shared_from_base<FilterNode>(), modified);
}
Status FilterNode::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["input_columns"] = input_columns_;
args["num_parallel_workers"] = num_workers_;
args["predicate"] = "pyfunc";
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -70,6 +70,15 @@ class FilterNode : public DatasetNode {
/// \return Status of the node visit
Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
/// \brief Getter functions
const std::shared_ptr<TensorOp> &Predicate() const { return predicate_; }
const std::vector<std::string> &InputColumns() const { return input_columns_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
std::shared_ptr<TensorOp> predicate_;
std::vector<std::string> input_columns_;

@ -138,8 +138,8 @@ Status MapNode::to_json(nlohmann::json *out_json) {
std::vector<nlohmann::json> ops;
std::vector<int32_t> cbs;
nlohmann::json op_args;
for (auto op : operations_) {
nlohmann::json op_args;
RETURN_IF_NOT_OK(op->to_json(&op_args));
op_args["tensor_op_name"] = op->Name();
ops.push_back(op_args);

@ -57,5 +57,11 @@ Status ProjectNode::Build(std::vector<std::shared_ptr<DatasetOp>> *const node_op
return Status::OK();
}
Status ProjectNode::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["columns"] = columns_;
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -55,6 +55,14 @@ class ProjectNode : public DatasetNode {
/// \return Status Status::OK() if all the parameters are valid
Status ValidateParams() override;
/// \brief Getter functions
const std::vector<std::string> &Columns() const { return columns_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
std::vector<std::string> columns_;
};

@ -29,7 +29,7 @@ namespace dataset {
class RootNode : public DatasetNode {
public:
/// \brief Constructor
RootNode() : DatasetNode() {}
RootNode() : DatasetNode(), num_epochs_(0) {}
/// \brief Constructor
explicit RootNode(std::shared_ptr<DatasetNode> child);

@ -83,5 +83,12 @@ Status SkipNode::AcceptAfter(IRNodePass *const p, bool *const modified) {
// Downcast shared pointer then call visitor
return p->VisitAfter(shared_from_base<SkipNode>(), modified);
}
Status SkipNode::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["count"] = skip_count_;
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -80,6 +80,14 @@ class SkipNode : public DatasetNode {
/// \return Status of the node visit
Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
/// \brief Getter functions
int32_t SkipCount() const { return skip_count_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
int32_t skip_count_;
};

@ -61,6 +61,12 @@ class AlbumNode : public MappableSourceNode {
/// \return Status Status::OK() if get shard id successfully
Status GetShardId(int32_t *shard_id) override;
/// \brief Getter functions
const std::string &DatasetDir() const { return dataset_dir_; }
const std::string &SchemaPath() const { return schema_path_; }
const std::vector<std::string> &ColumnNames() const { return column_names_; }
bool Decode() const { return decode_; }
private:
std::string dataset_dir_;
std::string schema_path_;

@ -144,5 +144,22 @@ Status CelebANode::GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size
return Status::OK();
}
Status CelebANode::to_json(nlohmann::json *out_json) {
nlohmann::json args, sampler_args;
RETURN_IF_NOT_OK(sampler_->to_json(&sampler_args));
args["sampler"] = sampler_args;
args["num_parallel_workers"] = num_workers_;
args["dataset_dir"] = dataset_dir_;
args["decode"] = decode_;
args["extensions"] = extensions_;
args["usage"] = usage_;
if (cache_ != nullptr) {
nlohmann::json cache_args;
RETURN_IF_NOT_OK(cache_->to_json(&cache_args));
args["cache"] = cache_args;
}
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -71,6 +71,17 @@ class CelebANode : public MappableSourceNode {
Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate,
int64_t *dataset_size) override;
/// \brief Getter functions
const std::string &DatasetDir() const { return dataset_dir_; }
const std::string &Usage() const { return usage_; }
bool Decode() const { return decode_; }
const std::set<std::string> &Extensions() const { return extensions_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
std::string dataset_dir_;
std::string usage_;

@ -95,5 +95,20 @@ Status Cifar100Node::GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &si
return Status::OK();
}
Status Cifar100Node::to_json(nlohmann::json *out_json) {
nlohmann::json args, sampler_args;
RETURN_IF_NOT_OK(sampler_->to_json(&sampler_args));
args["sampler"] = sampler_args;
args["num_parallel_workers"] = num_workers_;
args["dataset_dir"] = dataset_dir_;
args["usage"] = usage_;
if (cache_ != nullptr) {
nlohmann::json cache_args;
RETURN_IF_NOT_OK(cache_->to_json(&cache_args));
args["cache"] = cache_args;
}
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -69,6 +69,15 @@ class Cifar100Node : public MappableSourceNode {
Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate,
int64_t *dataset_size) override;
/// \brief Getter functions
const std::string &DatasetDir() const { return dataset_dir_; }
const std::string &Usage() const { return usage_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
std::string dataset_dir_;
std::string usage_;

@ -93,5 +93,20 @@ Status Cifar10Node::GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &siz
return Status::OK();
}
Status Cifar10Node::to_json(nlohmann::json *out_json) {
nlohmann::json args, sampler_args;
RETURN_IF_NOT_OK(sampler_->to_json(&sampler_args));
args["sampler"] = sampler_args;
args["num_parallel_workers"] = num_workers_;
args["dataset_dir"] = dataset_dir_;
args["usage"] = usage_;
if (cache_ != nullptr) {
nlohmann::json cache_args;
RETURN_IF_NOT_OK(cache_->to_json(&cache_args));
args["cache"] = cache_args;
}
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

@ -69,6 +69,15 @@ class Cifar10Node : public MappableSourceNode {
Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate,
int64_t *dataset_size) override;
/// \brief Getter functions
const std::string &DatasetDir() const { return dataset_dir_; }
const std::string &Usage() const { return usage_; }
/// \brief Get the arguments of node
/// \param[out] out_json JSON string of all attributes
/// \return Status of the function
Status to_json(nlohmann::json *out_json) override;
private:
std::string dataset_dir_;
std::string usage_;

@ -252,5 +252,23 @@ Status CLUENode::GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_g
return Status::OK();
}
Status CLUENode::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["num_parallel_workers"] = num_workers_;
args["dataset_dir"] = dataset_files_;
args["task"] = task_;
args["usage"] = usage_;
args["num_samples"] = num_samples_;
args["shuffle"] = shuffle_;
args["num_shards"] = num_shards_;
args["shard_id"] = shard_id_;
if (cache_ != nullptr) {
nlohmann::json cache_args;
RETURN_IF_NOT_OK(cache_->to_json(&cache_args));
args["cache"] = cache_args;
}
*out_json = args;
return Status::OK();
}
} // namespace dataset
} // namespace mindspore

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save