1 /** 2 * Copyright 2020-2022 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 class CocoNode : public MappableSourceNode { 29 public: 30 #ifdef ENABLE_PYTHON 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, py::function decrypt = py::none()); 35 #else 36 /// \brief Constructor. 37 CocoNode(const std::string &dataset_dir, const std::string &annotation_file, const std::string &task, 38 const bool &decode, const std::shared_ptr<SamplerObj> &sampler, std::shared_ptr<DatasetCache> cache, 39 const bool &extra_metadata); 40 #endif 41 42 /// \brief Destructor. 43 ~CocoNode() override = default; 44 45 /// \brief Node name getter. 46 /// \return Name of the current node. Name()47 std::string Name() const override { return kCocoNode; } 48 49 /// \brief Print the description. 50 /// \param[out] out The output stream to write output to. 51 void Print(std::ostream &out) const override; 52 53 /// \brief Copy the node to a new object. 54 /// \return A shared pointer to the new copy. 55 std::shared_ptr<DatasetNode> Copy() override; 56 57 /// \brief A base class override function to create the required runtime dataset op objects for this class. 58 /// \param[out] node_ops A vector containing shared pointer to the Dataset Ops that this object will create. 59 /// \return Status Status::OK() if build successfully. 60 Status Build(std::vector<std::shared_ptr<DatasetOp>> *const node_ops) override; 61 62 /// \brief Parameters validation. 63 /// \return Status Status::OK() if all the parameters are valid. 64 Status ValidateParams() override; 65 66 /// \brief Get the shard id of node. 67 /// \param[in] shard_id shard id. 68 /// \return Status Status::OK() if get shard id successfully. 69 Status GetShardId(int32_t *shard_id) override; 70 71 /// \brief Base-class override for GetDatasetSize. 72 /// \param[in] size_getter Shared pointer to DatasetSizeGetter. 73 /// \param[in] estimate This is only supported by some of the ops and it's used to speed up the process of getting 74 /// dataset size at the expense of accuracy. 75 /// \param[out] dataset_size the size of the dataset. 76 /// \return Status of the function. 77 Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate, 78 int64_t *dataset_size) override; 79 80 /// \brief Getter functions. DatasetDir()81 const std::string &DatasetDir() const { return dataset_dir_; } AnnotationFile()82 const std::string &AnnotationFile() const { return annotation_file_; } Task()83 const std::string &Task() const { return task_; } Decode()84 bool Decode() const { return decode_; } 85 86 /// \brief Get the arguments of node. 87 /// \param[out] out_json JSON string of all attributes. 88 /// \return Status of the function. 89 Status to_json(nlohmann::json *out_json) override; 90 91 #ifndef ENABLE_ANDROID 92 /// \brief Function to read dataset in json. 93 /// \param[in] json_obj The JSON object to be deserialized. 94 /// \param[out] ds Deserialized dataset. 95 /// \return Status The status code returned. 96 static Status from_json(nlohmann::json json_obj, std::shared_ptr<DatasetNode> *ds); 97 #endif 98 99 /// \brief Sampler getter. 100 /// \return SamplerObj of the current node. Sampler()101 std::shared_ptr<SamplerObj> Sampler() override { return sampler_; } 102 103 /// \brief Sampler setter. SetSampler(std::shared_ptr<SamplerObj> sampler)104 void SetSampler(std::shared_ptr<SamplerObj> sampler) override { sampler_ = sampler; } 105 106 private: 107 std::string dataset_dir_; 108 std::string annotation_file_; 109 std::string task_; 110 bool decode_; 111 std::shared_ptr<SamplerObj> sampler_; 112 bool extra_metadata_; 113 #ifdef ENABLE_PYTHON 114 py::function decrypt_; 115 #endif 116 }; 117 } // namespace dataset 118 } // namespace mindspore 119 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_COCO_NODE_H_ 120