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.CelebADataset.rst 6.7 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
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. mindspore.dataset.CelebADataset
  2. ===============================
  3. .. py:class:: mindspore.dataset.CelebADataset(dataset_dir, num_parallel_workers=None, shuffle=None, usage='all', sampler=None, decode=False, extensions=None, num_samples=None, num_shards=None, shard_id=None, cache=None)
  4. 用于读取和解析CelebA数据集的源数据文件。目前仅支持读取解析标注文件 `list_attr_celeba.txt` 作为数据集的标注。
  5. 生成的数据集有两列:`[image, attr]`。列: `image` 的数据类型为uint8。列: `attr` 的数据类型为uint32,并以one-hot编码的形式生成。
  6. **参数:**
  7. - **dataset_dir** (str) - 包含数据集文件的根目录路径。
  8. - **num_parallel_workers** (int,可选) - 指定读取数据的工作线程数(默认值None,即使用mindspore.dataset.config中配置的线程数)。
  9. - **shuffle** (bool,可选) - 是否混洗数据集(默认为None,下表中会展示不同配置的预期行为)。
  10. - **usage** (str,可选) - 指定数据集的子集,可取值为'train','valid','test'或'all'。(默认值为'all',即全部样本图片)。
  11. - **sampler** (Sampler,可选) - 指定从数据集中选取样本的采样器(默认为None,下表中会展示不同配置的预期行为)。
  12. - **decode** (bool,可选) - 是否对读取的图像进行解码操作(默认为False)。
  13. - **extensions** (list[str],可选) - 指定文件扩展后缀,仅读取这些后缀的文件到数据集中(默认为None)。
  14. - **num_samples** (int,可选) - 指定从数据集中读取的样本数(可以小于数据集总数,默认值为None,即全部样本图片)。
  15. - **num_shards** (int, 可选) - 指定分布式训练时将数据集进行划分的分片数(默认值None)。指定此参数后, `num_samples` 表示每个分片的最大样本数。
  16. - **shard_id** (int, 可选) - 指定分布式训练时使用的分片ID号(默认值None)。只有当指定了 `num_shards` 时才能指定此参数。
  17. - **cache** (DatasetCache, 可选) - 数据缓存客户端实例,用于加快数据集处理速度(默认为None,不使用缓存)。
  18. **异常:**
  19. - **RuntimeError** - 参数 `dataset_dir` 不包含任何数据文件。
  20. - **RuntimeError** - 参数 `num_parallel_workers` 超过系统最大线程数。
  21. - **RuntimeError** - 同时指定了 `sampler` 和 `shuffle` 。
  22. - **RuntimeError** - 同时指定了 `sampler` 和 `num_shards` 。
  23. - **RuntimeError** - 指定了 `num_shards` 参数,但是未指定 `shard_id` 参数。
  24. - **RuntimeError** - 指定了 `shard_id` 参数,但是未指定 `num_shards` 参数。
  25. - **ValueError** - `shard_id` 参数错误(小于0或者大于等于 `num_shards` )。
  26. .. note:: 此数据集可以指定 `sampler` 参数,但 `sampler` 和 `shuffle` 是互斥的。下表展示了几种合法的输入参数及预期的行为。
  27. .. list-table:: 配置 `sampler` 和 `shuffle` 的不同组合得到的预期排序结果
  28. :widths: 25 25 50
  29. :header-rows: 1
  30. * - 参数 `sampler`
  31. - 参数 `shuffle`
  32. - 预期数据顺序
  33. * - None
  34. - None
  35. - 随机排列
  36. * - None
  37. - True
  38. - 随机排列
  39. * - None
  40. - False
  41. - 顺序排列
  42. * - 参数 `sampler`
  43. - None
  44. - 由 `sampler` 行为定义的顺序
  45. * - 参数 `sampler`
  46. - True
  47. - 不允许
  48. * - 参数 `sampler`
  49. - False
  50. - 不允许
  51. **样例:**
  52. >>> celeba_dataset_dir = "/path/to/celeba_dataset_directory"
  53. >>>
  54. >>> # 从CelebA数据集中随机读取5个样本图片
  55. >>> dataset = ds.CelebADataset(dataset_dir=celeba_dataset_dir, usage='train', num_samples=5)
  56. >>>
  57. >>> # 注:在生成的数据集对象中,每一次迭代得到的数据行都有"image"和"attr" 两个键
  58. **关于CelebA数据集:**
  59. CelebFaces Attributes Dataset(CelebA)数据集是一个大规模的人脸属性数据集,拥有超过20万名人图像,每个图像都有40个属性标注。此数据集包含了大量不同姿态、各种背景的人脸图像,种类丰富、数量庞大、标注充分。数据集总体包含:
  60. - 10177个不同的身份
  61. - 202599张人脸图像
  62. - 每张图像拥有5个五官位置标注,40个属性标签。
  63. 此数据集可用于各种计算机视觉任务的训练和测试,包括人脸识别、人脸检测、五官定位、人脸编辑和合成等。
  64. 原始CelebA数据集结构:
  65. .. code-block::
  66. .
  67. └── CelebA
  68. ├── README.md
  69. ├── Img
  70. │ ├── img_celeba.7z
  71. │ ├── img_align_celeba_png.7z
  72. │ └── img_align_celeba.zip
  73. ├── Eval
  74. │ └── list_eval_partition.txt
  75. └── Anno
  76. ├── list_landmarks_celeba.txt
  77. ├── list_landmarks_align_celeba.txt
  78. ├── list_bbox_celeba.txt
  79. ├── list_attr_celeba.txt
  80. └── identity_CelebA.txt
  81. 您可以将数据集解压成如下的文件结构,并通过MindSpore的API进行读取。
  82. .. code-block::
  83. .
  84. └── celeba_dataset_directory
  85. ├── list_attr_celeba.txt
  86. ├── 000001.jpg
  87. ├── 000002.jpg
  88. ├── 000003.jpg
  89. ├── ...
  90. **引用:**
  91. .. code-block::
  92. @article{DBLP:journals/corr/LiuLWT14,
  93. author = {Ziwei Liu and Ping Luo and Xiaogang Wang and Xiaoou Tang},
  94. title = {Deep Learning Face Attributes in the Wild},
  95. journal = {CoRR},
  96. volume = {abs/1411.7766},
  97. year = {2014},
  98. url = {http://arxiv.org/abs/1411.7766},
  99. archivePrefix = {arXiv},
  100. eprint = {1411.7766},
  101. timestamp = {Tue, 10 Dec 2019 15:37:26 +0100},
  102. biburl = {https://dblp.org/rec/journals/corr/LiuLWT14.bib},
  103. bibsource = {dblp computer science bibliography, https://dblp.org},
  104. howpublished = {http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html}
  105. }
  106. .. include:: mindspore.dataset.Dataset.add_sampler.rst
  107. .. include:: mindspore.dataset.Dataset.rst
  108. .. include:: mindspore.dataset.Dataset.use_sampler.rst
  109. .. include:: mindspore.dataset.Dataset.zip.rst