Function mindspore::dataset::Coco
Defined in File datasets.h
Function Documentation
Function to create a CocoDataset.
Note
The generated dataset has multi-columns :
task=’Detection’, column: [[‘image’, dtype=uint8], [‘bbox’, dtype=float32], [‘category_id’, dtype=uint32], [‘iscrowd’, dtype=uint32]].
task=’Stuff’, column: [[‘image’, dtype=uint8], [‘segmentation’,dtype=float32], [‘iscrowd’, dtype=uint32]].
task=’Keypoint’, column: [[‘image’, dtype=uint8], [‘keypoints’, dtype=float32], [‘num_keypoints’, dtype=uint32]].
task=’Panoptic’, column: [[‘image’, dtype=uint8], [‘bbox’, dtype=float32], [‘category_id’, dtype=uint32], [‘iscrowd’, dtype=uint32], [‘area’, dtype=uitn32]].
task=’Captioning’, column: [[‘image’, dtype=uint8], [‘captions’, dtype=string]].
- Parameters
dataset_dir – [in] Path to the root directory that contains the dataset.
annotation_file – [in] Path to the annotation json.
task – [in] Set the task type of reading coco data. Supported task types are “Detection”, “Stuff”, “Panoptic”, “Keypoint” and “Captioning”.
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 CocoDataset.
样例/* Define dataset path and MindData object */ std::string folder_path = "/path/to/coco_dataset_directory"; std::string annotation_file = "/path/to/annotation_file"; std::shared_ptr<Dataset> ds = Coco(folder_path, annotation_file); /* 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 COCO dataset, each dictionary has keys "image" and "annotation" */ auto image = row["image"];