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.VOCDataset.rst 8.7 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. mindspore.dataset.VOCDataset
  2. =============================
  3. .. py:class:: mindspore.dataset.VOCDataset(dataset_dir, task='Segmentation', usage='train', class_indexing=None, 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. 读取和解析VOC数据集的源文件构建数据集。
  5. **参数:**
  6. - **dataset_dir** (str): 包含数据集文件的根目录的路径。
  7. - **task** (str, 可选): 指定读取VOC数据的任务类型,现在只支持'Segmentation'和'Detection'。默认值:'Segmentation'。
  8. - **usage** (str, 可选): 指定数据集的子集,默认值:'train'。
  9. - 如果 'task' 的值为 'Segmentation',则读取 'ImageSets/Segmentation/' 目录下定义的图片和label信息;
  10. - 如果 'task' 的值为 'Detection' ,则读取 'ImageSets/Main/' 目录下定义的图片和label信息。
  11. - **class_indexing** (dict, 可选): 指定一个从label名称到label索引的映射,要求映射规则为string到int。索引值从0开始,并且要求每个label名称对应的索引值唯一。
  12. 仅在 'Detection' 任务中有效。默认值:None,不指定。
  13. - **num_samples** (int, 可选): 指定从数据集中读取的样本数。默认值:None,所有图像样本。
  14. - **num_parallel_workers** (int, 可选) - 指定读取数据的工作线程数。默认值:None,使用mindspore.dataset.config中配置的线程数。
  15. - **shuffle** (bool, 可选) - 是否混洗数据集。默认值:None,下表中会展示不同参数配置的预期行为。
  16. - **decode** (bool, 可选) - 是否对读取的图片进行解码操作,默认值:False,不解码。
  17. - **sampler** (Sampler, 可选) - 指定从数据集中选取样本的采样器,默认值:None,下表中会展示不同配置的预期行为。
  18. - **num_shards** (int, 可选) - 指定分布式训练时将数据集进行划分的分片数,默认值:None。指定此参数后, `num_samples` 表示每个分片的最大样本数。
  19. - **shard_id** (int, 可选) - 指定分布式训练时使用的分片ID号,默认值:None。只有当指定了 `num_shards` 时才能指定此参数。
  20. - **cache** (DatasetCache, 可选) - 单节点数据缓存服务,用于加快数据集处理,详情请阅读`单节点数据缓存 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/cache.html>`_ 。默认值:None,不使用缓存。
  21. - **extra_metadata** (bool, 可选) - 用于指定是否额外输出一个数据列用于表示图片元信息。如果为True,则将额外输出一个名为 `[_meta-filename, dtype=string]` 的数据列,默认值:False。
  22. 根据给定的`task`配置,生成数据集具有不同的输出列:
  23. - `task` = 'Detection',输出列: `[image, dtype=uint8]`, `[bbox, dtype=float32]`, `[label, dtype=uint32]`, `[difficult, dtype=uint32]`, `[truncate, dtype=uint32]`。
  24. - `task` = 'Segmentation',输出列: `[image, dtype=uint8]`, `[target, dtype=uint8]`。
  25. **异常:**
  26. - **RuntimeError** - `dataset_dir` 路径下不包含任何数据文件。
  27. - **RuntimeError** - `num_parallel_workers` 参数超过系统最大线程数。
  28. - **RuntimeError** - 读取的xml文件格式异常或无效。
  29. - **RuntimeError** - 读取的xml文件缺失 `object` 属性。
  30. - **RuntimeError** - 读取的xml文件缺失 `bndbox` 属性。
  31. - **RuntimeError** - 同时指定了 `sampler` 和 `shuffle` 参数。
  32. - **RuntimeError** - 同时指定了 `sampler` 和 `num_shards` 参数。
  33. - **RuntimeError** - 指定了 `num_shards` 参数,但是未指定 `shard_id` 参数。
  34. - **RuntimeError** - 指定了 `shard_id` 参数,但是未指定 `num_shards` 参数。
  35. - **ValueError** - 指定的任务不为'Segmentation'或'Detection'。
  36. - **ValueError** - 指定任务为'Segmentation'时, `class_indexing` 参数不为None。
  37. - **ValueError** - 与 `usage` 参数相关的txt文件不存在。
  38. - **ValueError** - `shard_id` 参数值错误(小于0或者大于等于 `num_shards` )。
  39. .. note::
  40. - 当参数 `extra_metadata` 为True时,还需使用 `rename` 操作删除额外数据列'_meta-filename'的前缀'_meta-',
  41. 否则迭代得到的数据行中不会出现此额外数据列。
  42. - 此数据集可以指定参数 `sampler` ,但参数 `sampler` 和参数 `shuffle` 的行为是互斥的。下表展示了几种合法的输入参数组合及预期的行为。
  43. .. list-table:: 配置 `sampler` 和 `shuffle` 的不同组合得到的预期排序结果
  44. :widths: 25 25 50
  45. :header-rows: 1
  46. * - 参数 `sampler`
  47. - 参数 `shuffle`
  48. - 预期数据顺序
  49. * - None
  50. - None
  51. - 随机排列
  52. * - None
  53. - True
  54. - 随机排列
  55. * - None
  56. - False
  57. - 顺序排列
  58. * - `sampler` 实例
  59. - None
  60. - 由 `sampler` 行为定义的顺序
  61. * - `sampler` 实例
  62. - True
  63. - 不允许
  64. * - `sampler` 实例
  65. - False
  66. - 不允许
  67. **样例:**
  68. >>> voc_dataset_dir = "/path/to/voc_dataset_directory"
  69. >>>
  70. >>> # 1) 读取VOC数据的Segmentation任务中的train部分进行训练
  71. >>> dataset = ds.VOCDataset(dataset_dir=voc_dataset_dir, task="Segmentation", usage="train")
  72. >>>
  73. >>> # 2) 读取VOC数据的Detection任务中的train部分进行训练
  74. >>> dataset = ds.VOCDataset(dataset_dir=voc_dataset_dir, task="Detection", usage="train")
  75. >>>
  76. >>> # 3) 以8个线程随机顺序读取voc_dataset_dir中的所有VOC数据集样本
  77. >>> dataset = ds.VOCDataset(dataset_dir=voc_dataset_dir, task="Detection", usage="train",
  78. ... num_parallel_workers=8)
  79. >>>
  80. >>> # 4) 读voc_dataset_dir中的所有VOC数据集图片样本,且对图像进行解码
  81. >>> dataset = ds.VOCDataset(dataset_dir=voc_dataset_dir, task="Detection", usage="train",
  82. ... decode=True, shuffle=False)
  83. >>>
  84. >>> # 在VOC数据集中,如果task='Segmentation',每一次迭代得到的数据行都有"image"和"target"两个键。
  85. >>> # 在VOC数据集中,如果task='Detection',每一次迭代得到的数据行都有"image"和"annotation"两个键。
  86. **关于VOC数据集:**
  87. PASCAL Visual Object Classes(VOC)是视觉目标识别和检测的挑战赛,它为视觉和机器学习社区提供了图像和标注的标准数据集,称为VOC数据集。
  88. 您可以解压缩原始VOC-2012数据集文件到如下目录结构,并通过MindSpore的API进行读取。
  89. .. code-block::
  90. .
  91. └── voc2012_dataset_dir
  92. ├── Annotations
  93. │ ├── 2007_000027.xml
  94. │ ├── 2007_000032.xml
  95. │ ├── ...
  96. ├── ImageSets
  97. │ ├── Action
  98. │ ├── Layout
  99. │ ├── Main
  100. │ └── Segmentation
  101. ├── JPEGImages
  102. │ ├── 2007_000027.jpg
  103. │ ├── 2007_000032.jpg
  104. │ ├── ...
  105. ├── SegmentationClass
  106. │ ├── 2007_000032.png
  107. │ ├── 2007_000033.png
  108. │ ├── ...
  109. └── SegmentationObject
  110. ├── 2007_000032.png
  111. ├── 2007_000033.png
  112. ├── ...
  113. **引用:**
  114. .. code-block::
  115. @article{Everingham10,
  116. author = {Everingham, M. and Van~Gool, L. and Williams, C. K. I. and Winn, J. and Zisserman, A.},
  117. title = {The Pascal Visual Object Classes (VOC) Challenge},
  118. journal = {International Journal of Computer Vision},
  119. volume = {88},
  120. year = {2012},
  121. number = {2},
  122. month = {jun},
  123. pages = {303--338},
  124. biburl = {http://host.robots.ox.ac.uk/pascal/VOC/pubs/everingham10.html#bibtex},
  125. howpublished = {http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html}
  126. }
  127. .. include:: mindspore.dataset.Dataset.add_sampler.rst
  128. .. include:: mindspore.dataset.Dataset.rst
  129. .. include:: mindspore.dataset.Dataset.use_sampler.rst
  130. .. include:: mindspore.dataset.Dataset.zip.rst