1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_COCO_NODE_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_COCO_NODE_H_ 19 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "minddata/dataset/engine/ir/datasetops/dataset_node.h" 25 26 namespace mindspore { 27 namespace dataset { 28 29 class CocoNode : public MappableSourceNode { 30 public: 31 /// \brief Constructor 32 CocoNode(const std::string &dataset_dir, const std::string &annotation_file, const std::string &task, 33 const bool &decode, const std::shared_ptr<SamplerObj> &sampler, std::shared_ptr<DatasetCache> cache, 34 const bool &extra_metadata); 35 36 /// \brief Destructor 37 ~CocoNode() = default; 38 39 /// \brief Node name getter 40 /// \return Name of the current node Name()41 std::string Name() const override { return kCocoNode; } 42 43 /// \brief Print the description 44 /// \param out - The output stream to write output to 45 void Print(std::ostream &out) const override; 46 47 /// \brief Copy the node to a new object 48 /// \return A shared pointer to the new copy 49 std::shared_ptr<DatasetNode> Copy() override; 50 51 /// \brief a base class override function to create the required runtime dataset op objects for this class 52 /// \param node_ops - A vector containing shared pointer to the Dataset Ops that this object will create 53 /// \return Status Status::OK() if build successfully 54 Status Build(std::vector<std::shared_ptr<DatasetOp>> *const node_ops) override; 55 56 /// \brief Parameters validation 57 /// \return Status Status::OK() if all the parameters are valid 58 Status ValidateParams() override; 59 60 /// \brief Get the shard id of node 61 /// \return Status Status::OK() if get shard id successfully 62 Status GetShardId(int32_t *shard_id) override; 63 64 /// \brief Base-class override for GetDatasetSize 65 /// \param[in] size_getter Shared pointer to DatasetSizeGetter 66 /// \param[in] estimate This is only supported by some of the ops and it's used to speed up the process of getting 67 /// dataset size at the expense of accuracy. 68 /// \param[out] dataset_size the size of the dataset 69 /// \return Status of the function 70 Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate, 71 int64_t *dataset_size) override; 72 73 /// \brief Getter functions DatasetDir()74 const std::string &DatasetDir() const { return dataset_dir_; } AnnotationFile()75 const std::string &AnnotationFile() const { return annotation_file_; } Task()76 const std::string &Task() const { return task_; } Decode()77 bool Decode() const { return decode_; } 78 79 /// \brief Get the arguments of node 80 /// \param[out] out_json JSON string of all attributes 81 /// \return Status of the function 82 Status to_json(nlohmann::json *out_json) override; 83 84 #ifndef ENABLE_ANDROID 85 /// \brief Function to read dataset in json 86 /// \param[in] json_obj The JSON object to be deserialized 87 /// \param[out] ds Deserialized dataset 88 /// \return Status The status code returned 89 static Status from_json(nlohmann::json json_obj, std::shared_ptr<DatasetNode> *ds); 90 #endif 91 92 /// \brief Sampler getter 93 /// \return SamplerObj of the current node Sampler()94 std::shared_ptr<SamplerObj> Sampler() override { return sampler_; } 95 96 /// \brief Sampler setter SetSampler(std::shared_ptr<SamplerObj> sampler)97 void SetSampler(std::shared_ptr<SamplerObj> sampler) override { sampler_ = sampler; } 98 99 private: 100 std::string dataset_dir_; 101 std::string annotation_file_; 102 std::string task_; 103 bool decode_; 104 std::shared_ptr<SamplerObj> sampler_; 105 bool extra_metadata_; 106 }; 107 108 } // namespace dataset 109 } // namespace mindspore 110 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_COCO_NODE_H_ 111