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.4 kB

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