Function mindspore::dataset::VOC

Function Documentation

inline std::shared_ptr<VOCDataset> mindspore::dataset::VOC(const std::string &dataset_dir, const std::string &task = "Segmentation", const std::string &usage = "train", const std::map<std::string, int32_t> &class_indexing = {}, bool decode = false, const std::shared_ptr<Sampler> &sampler = std::make_shared<RandomSampler>(), const std::shared_ptr<DatasetCache> &cache = nullptr, bool extra_metadata = false)

Function to create a VOCDataset.

Note

The generated dataset has multi-columns :

  • task=’Detection’, column: [[‘image’, dtype=uint8], [‘bbox’, dtype=float32], [‘label’, dtype=uint32], [‘difficult’, dtype=uint32], [‘truncate’, dtype=uint32]].

  • task=’Segmentation’, column: [[‘image’, dtype=uint8], [‘target’,dtype=uint8]].

Parameters
  • dataset_dir[in] Path to the root directory that contains the dataset.

  • task[in] Set the task type of reading voc data, now only support “Segmentation” or “Detection”.

  • usage[in] The type of data list text file to be read (default = “train”).

  • class_indexing[in] A str-to-int mapping from label name to index, only valid in “Detection” task.

  • decode[in] Decode the images after reading.

  • sampler[in] Shared pointer to a sampler object used to choose samples from the dataset. If sampler is not given, a RandomSampler will be used to randomly iterate the entire dataset (default = RandomSampler()).

  • cache[in] Tensor cache to use (default=nullptr which means no cache is used).

  • extra_metadata[in] Flag to add extra meta-data to row (default=false).

Returns

Shared pointer to the VOCDataset.

样例
/* Define dataset path and MindData object */
std::string folder_path = "/path/to/voc_dataset_directory";
std::shared_ptr<Dataset> ds = VOC(folder_path, "Detection", "train", {}, false,
                                  std::make_shared<SequentialSampler>(0, 6));

/* Create iterator to read dataset */
std::shared_ptr<Iterator> iter = ds->CreateIterator();
std::unordered_map<std::string, mindspore::MSTensor> row;
iter->GetNextRow(&row);

/* Note: In VOC dataset, if task='Segmentation', each dictionary has keys "image" and "target" */
/* Note: In VOC dataset, if task='Detection', each dictionary has keys "image" and "annotation" */
auto image = row["image"];