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.WeightedRandomSampler.rst 1.5 kB

1234567891011121314151617181920212223242526272829303132
  1. mindspore.dataset.WeightedRandomSampler
  2. =======================================
  3. .. py:class:: mindspore.dataset.WeightedRandomSampler(weights, num_samples=None, replacement=True)
  4. 给定样本的权重列表,根据权重决定样本的采样概率,随机采样[0,len(weights) - 1]中的样本。
  5. **参数:**
  6. - **weights** (list[float, int]) - 权重序列,总和不一定为1。
  7. - **num_samples** (int, 可选) - 获取的样本数,可用于部分获取采样得到的样本。默认值:None,获取采样到的所有样本。
  8. - **replacement** (bool) - 是否将样本ID放回下一次采样,默认值:True,有放回采样。
  9. **异常:**
  10. - **TypeError:** `weights` 元素的类型不是数字。
  11. - **TypeError:** `num_samples` 不是整数值。
  12. - **TypeError:** `replacement` 不是布尔值。
  13. - **RuntimeError:** `weights` 为空或全为零。
  14. - **ValueError:** `num_samples` 为负值。
  15. **样例:**
  16. >>> weights = [0.9, 0.01, 0.4, 0.8, 0.1, 0.1, 0.3]
  17. >>>
  18. >>> # 创建一个WeightedRandomSampler,将对4个元素进行有放回采样
  19. >>> sampler = ds.WeightedRandomSampler(weights, 4)
  20. >>> dataset = ds.ImageFolderDataset(image_folder_dataset_dir,
  21. ... num_parallel_workers=8,
  22. ... sampler=sampler)
  23. .. include:: mindspore.dataset.BuiltinSampler.rst