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