当前位置:网站首页>使用MindSpore多数据集混合采样并加载
使用MindSpore多数据集混合采样并加载
2022-06-10 04:31:00 【MSofficial】
问题描述:
【功能模块】
Mindspore 1.5
【操作步骤&问题现象】
1、对比学习中需要载入正例与负例,来源于不同的数据集 PosDataSet 以及 NegDataSet,并且 两者的样本量不一致,现使用分别对着两个数据集使用RandomSampler采样
使用 batch 分别将数据集处理为 PosBatchDataSet 以及 NegBatchDataSet
2、为了使用Model的多卡并行功能,现需要将两个数据集合并为同一个数据集, 当 原PosBatchDataSet 或者 NegBatchDataSet 的batchSize为 64 时 ,希望合并后的数据集的batchSize为 128,其中前 64 个数据来源于 PosBatchDataSet, 后64个 来源于NegBatchDataSet
3. 问题:
a. 合并数据集是否可行,若可行可否提供参考
b. 是否可以使用DistributedSampler使用多机
c. 由于PosDataSet 以及 NegDataSet样本量不一致, 是否可以指定NegDataSet 重复采样,直到 PosDataSet 非重复采样结束
【截图信息】
class MakeDataset:
def __init__(self, length):
self.length = length
self.A = [np.ones((2, 2)) for _ in range(length)]
self.B = np.arange(length)
def __getitem__(self, index):
return self.A[index], self.B[index]
def __len__(self):
return self.length
batch_size = 64
pos_data_set = MakeDataset(1000)
neg_data_set = MakeDataset(1000)
pos_data_set = GeneratorDataset(pos_data_set, column_names=["A", "B"])
neg_data_set = GeneratorDataset(neg_data_set, column_names=["A", "B"])
pos_batch_data_set = pos_data_set.batch(batch_size)
neg_batch_data_set = neg_data_set.batch(batch_size)
# Merge(pos_batch_data_set, neg_batch_data_set)
解答:
建议把 NegBatchData 和 PosBatchData 放到同一个 MakeDataset里面,然后自己控制 NegSample -> NegBatch 和 PosSample -> PosBatch的逻辑,以及重复采样也可以在 __getitem__里面控制实现。即:通过MakeDataset 输出的就是已经混合好的 Batch。 按照上面的逻辑,只有一个MakeDataset,是可以使用 DistributedSampler的。
边栏推荐
- Why do SQL statements use indexes but still slow queries?
- 电阻电容封装选型经验详解
- Fastapi-16-page beautification-1
- [understanding of opportunity -22]: Guiguzi - the art of closing Tibet. Collect your talents in time to protect yourself in the workplace, business and business activities
- Gui编程学生成绩管理系统
- 什么时候用@ComponentScan?与@MapperScan有什么区别?
- [从零开始学习FPGA编程-13]:快速入门篇 - 操作步骤3(功能仿真)-2-Mentor HDL仿真工具modelsim工具的简介、功能仿真的基本原理
- Yyds dry goods inventory solution sword finger offer: rectangular coverage
- pytorch的add_module(name,module)用mindspore怎么表示
- epoll的两种模式和epoll反应堆
猜你喜欢

Jmeter测试TCP百万连接

Storage engine of MySQL database

Today, 19:30 | graphics special session - Gao Lin's team from Institute of computing technology, Chinese Academy of Sciences

Celery | 任务队列神器

Crack the five myths of programmers, and new programmer 004 is officially launched!

IO被谁吃了?

Puzzling color deviation of unity illumination black

JMeter testing TCP million connections
Webcodecs parsing GIF graph

How to view Scala source code in idea
随机推荐
这些编程语言老了,差不多死透了,年轻人不能碰
电阻电容封装选型经验详解
Zero basic network: command line (CLI) debugging firewall practice
What are the advantages of multi merchant mall applet source code?
[in depth study of 4g/5g/6g topic -28]: 5g NR startup process 4.6 - msg5 (rrcsetupcomplete) message scheduling
超好用的 Chrome 插件!
idea中怎样关联查看Scala源代码
[Android L]SEAndroid增强Androd安全性背景概要及带来的影响
FastApi-15-文件上传-3
Fastapi-16-page beautification-1
如何用天气预警API接口进行快速开发
JDBC 入门示例
APISpace 分钟级降水预报API接口 免费好用
Two modes of epoll and epoll reactor
Fastapi-14-file upload-2
[深入研究4G/5G/6G专题-28]: 5G NR开机流程4.6 - MSG5 (RRCSetupComplete)消息的调度
Today, 19:30 | graphics special session - Gao Lin's team from Institute of computing technology, Chinese Academy of Sciences
idea中怎样编写Scala代码
Getting started with JDBC example
[in depth study of 4g/5g/6g topic -25]: 5g NR startup process 4.3 - first scheduling of RRC connection request message msg3/rrcsetuprequest and Pusch uplink channel