You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.dataset.CocoDataset.rst 10 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. mindspore.dataset.CocoDataset
  2. ==============================
  3. .. py:class:: mindspore.dataset.CocoDataset(dataset_dir, annotation_file, task='Detection', num_samples=None, num_parallel_workers=None, shuffle=None, decode=False, sampler=None, num_shards=None, shard_id=None, cache=None, extra_metadata=False)
  4. 读取和解析COCO数据集的源文件构建数据集。该API支持解析COCO2017数据集,支持四种类型的机器学习任务,分别是目标检测、关键点检测、物体分割和全景分割。
  5. **参数:**
  6. - **dataset_dir** (str) - 包含数据集文件的根目录路径。
  7. - **annotation_file** (str) - 数据集标注JSON文件的路径。
  8. - **task** (str, 可选) - 指定COCO数据的任务类型。支持的任务类型包括:'Detection'、'Stuff' 、'Panoptic'和'Keypoint'。默认值:'Detection'。
  9. - **num_samples** (int, 可选) - 指定从数据集中读取的样本数,可以小于数据集总数。默认值:None,全部样本图片。
  10. - **num_parallel_workers** (int, 可选) - 指定读取数据的工作线程数,默认值:使用mindspore.dataset.config中配置的线程数。
  11. - **shuffle** (bool, 可选) - 是否混洗数据集。默认值:None,表2中会展示不同参数配置的预期行为。
  12. - **decode** (bool, 可选) - 是否对读取的图片进行解码操作,默认值:False,不解码。
  13. - **sampler** (Sampler, 可选) - 指定从数据集中选取样本的采样器,默认值:None,表2中会展示不同配置的预期行为。
  14. - **num_shards** (int, 可选) - 指定分布式训练时将数据集进行划分的分片数,默认值:None。指定此参数后, `num_samples` 表示每个分片的最大样本数。
  15. - **shard_id** (int, 可选) - 指定分布式训练时使用的分片ID号,默认值:None。只有当指定了 `num_shards` 时才能指定此参数。
  16. - **cache** (DatasetCache, 可选) - 单节点数据缓存服务,用于加快数据集处理,详情请阅读 `单节点数据缓存 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/cache.html>`_ 。默认值:None,不使用缓存。
  17. - **extra_metadata** (bool, 可选) - 用于指定是否额外输出一个数据列用于表示图片元信息。如果为True,则将额外输出一个名为 `[_meta-filename, dtype=string]` 的数据列,默认值:False。
  18. [表1] 根据不同 `task` 参数设置,生成数据集具有不同的输出列:
  19. +-------------------------+----------------------------------------------+
  20. | `task` | 输出列 |
  21. +=========================+==============================================+
  22. | Detection | [image, dtype=uint8] |
  23. | | |
  24. | | [bbox, dtype=float32] |
  25. | | |
  26. | | [category_id, dtype=uint32] |
  27. | | |
  28. | | [iscrowd, dtype=uint32] |
  29. +-------------------------+----------------------------------------------+
  30. | Stuff | [image, dtype=uint8] |
  31. | | |
  32. | | [segmentation, dtype=float32] |
  33. | | |
  34. | | [iscrowd, dtype=uint32] |
  35. +-------------------------+----------------------------------------------+
  36. | Keypoint | [image, dtype=uint8] |
  37. | | |
  38. | | [keypoints, dtype=float32] |
  39. | | |
  40. | | [num_keypoints, dtype=uint32] |
  41. +-------------------------+----------------------------------------------+
  42. | Panoptic | [image, dtype=uint8] |
  43. | | |
  44. | | [bbox, dtype=float32] |
  45. | | |
  46. | | [category_id, dtype=uint32] |
  47. | | |
  48. | | [iscrowd, dtype=uint32] |
  49. | | |
  50. | | [area, dtype=uint32] |
  51. +-------------------------+----------------------------------------------+
  52. **异常:**
  53. - **RuntimeError** - `dataset_dir` 路径下不包含任何数据文件。
  54. - **RuntimeError** - 同时指定了 `sampler` 和 `shuffle` 参数。
  55. - **RuntimeError** - 同时指定了 `sampler` 和 `num_shards` 参数或同时指定了 `sampler` 和 `shard_id` 参数。
  56. - **RuntimeError** - 指定了 `num_shards` 参数,但是未指定 `shard_id` 参数。
  57. - **RuntimeError** - 指定了 `shard_id` 参数,但是未指定 `num_shards` 参数。
  58. - **RuntimeError** - 解析 `annotation_file` 指定的JSON文件失败。
  59. - **ValueError** - `num_parallel_workers` 参数超过系统最大线程数。
  60. - **ValueError** - `task` 参数取值不为 `Detection` 、 `Stuff` 、`Panoptic` 或 `Keypoint` 。
  61. - **ValueError** - `annotation_file` 参数对应的文件不存在。
  62. - **ValueError** - `dataset_dir` 参数路径不存在。
  63. - **ValueError** - `shard_id` 参数值错误(小于0或者大于等于 `num_shards` )。
  64. .. note::
  65. - 当参数 `extra_metadata` 为True时,还需使用 `rename` 操作删除额外数据列'_meta-filename'的前缀'_meta-',
  66. 否则迭代得到的数据行中不会出现此额外数据列。
  67. - CocoDataset的 `sampler` 参数不支持指定PKSampler。
  68. - 此数据集可以指定参数 `sampler` ,但参数 `sampler` 和参数 `shuffle` 的行为是互斥的。下表展示了几种合法的输入参数组合及预期的行为。
  69. .. list-table:: [表2] 配置 `sampler` 和 `shuffle` 的不同组合得到的预期排序结果
  70. :widths: 25 25 50
  71. :header-rows: 1
  72. * - 参数 `sampler`
  73. - 参数 `shuffle`
  74. - 预期数据顺序
  75. * - None
  76. - None
  77. - 随机排列
  78. * - None
  79. - True
  80. - 随机排列
  81. * - None
  82. - False
  83. - 顺序排列
  84. * - `sampler` 实例
  85. - None
  86. - 由 `sampler` 行为定义的顺序
  87. * - `sampler` 实例
  88. - True
  89. - 不允许
  90. * - `sampler` 实例
  91. - False
  92. - 不允许
  93. **关于COCO数据集:**
  94. Microsoft Common Objects in Context(COCO)是一个大型数据集,该数据集专门为目标检测,语义分割和字幕生成任务而设计。它拥有330K张图像(标记数量大于200K个)、1500000个目标实例、80个目标类别、91个对象类别、每张图片均有5个字幕、带关键点标注的人有250000个。与流行的ImageNet数据集相比,COCO的类别较少,但每个类别中的图片样本非常多。
  95. 您可以解压缩原始COCO-2017数据集文件得到如下目录结构,并通过MindSpore的API读取。
  96. .. code-block::
  97. .
  98. └── coco_dataset_directory
  99. ├── train2017
  100. │ ├── 000000000009.jpg
  101. │ ├── 000000000025.jpg
  102. │ ├── ...
  103. ├── test2017
  104. │ ├── 000000000001.jpg
  105. │ ├── 000000058136.jpg
  106. │ ├── ...
  107. ├── val2017
  108. │ ├── 000000000139.jpg
  109. │ ├── 000000057027.jpg
  110. │ ├── ...
  111. └── annotation
  112. ├── captions_train2017.json
  113. ├── captions_val2017.json
  114. ├── instances_train2017.json
  115. ├── instances_val2017.json
  116. ├── person_keypoints_train2017.json
  117. └── person_keypoints_val2017.json
  118. **引用:**
  119. .. code-block::
  120. @article{DBLP:journals/corr/LinMBHPRDZ14,
  121. author = {Tsung{-}Yi Lin and Michael Maire and Serge J. Belongie and
  122. Lubomir D. Bourdev and Ross B. Girshick and James Hays and
  123. Pietro Perona and Deva Ramanan and Piotr Doll{\'{a}}r and C. Lawrence Zitnick},
  124. title = {Microsoft {COCO:} Common Objects in Context},
  125. journal = {CoRR},
  126. volume = {abs/1405.0312},
  127. year = {2014},
  128. url = {http://arxiv.org/abs/1405.0312},
  129. archivePrefix = {arXiv},
  130. eprint = {1405.0312},
  131. timestamp = {Mon, 13 Aug 2018 16:48:13 +0200},
  132. biburl = {https://dblp.org/rec/journals/corr/LinMBHPRDZ14.bib},
  133. bibsource = {dblp computer science bibliography, https://dblp.org}
  134. }
  135. .. include:: mindspore.dataset.Dataset.add_sampler.rst
  136. .. include:: mindspore.dataset.Dataset.rst
  137. .. include:: mindspore.dataset.Dataset.d.rst
  138. .. include:: mindspore.dataset.Dataset.use_sampler.rst
  139. .. include:: mindspore.dataset.Dataset.zip.rst