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