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