通常,当我们在pytorch中加载数据时,我们执行以下操作
for x, y in dataloaders:
# Do something
但是,在这个名为MusicNet的数据集中,它们声明自己的数据集和数据加载器,如下所示
^{pr2}$然后像这样加载数据
with train_set, test_set:
for i, (x, y) in enumerate(train_loader):
# Do something
我不明白为什么没有with train_set, test_set
行代码就不能工作。在
另外,如何访问数据?在
我试过了
train_set.access(2560,0)
以及
with train_set, test_set:
x, y = train_set.access(2560,0)
他们要么给我一个错误信息
KeyError Traceback (most recent call last) in ----> 1 train_set.access(2560,0)
/workspace/raven_data/AMT/MusicNet/pytorch_musicnet/musicnet.py in access(self, rec_id, s, shift, jitter) 106 107 if self.mmap: --> 108 x = np.frombuffer(self.records[rec_id][0][ssz_float:int(s+scaleself.window)*sz_float], dtype=np.float32).copy() 109 else: 110 fid,_ = self.records[rec_id]
KeyError: 2560
或者给我一个空的x
和{
为了能够将^{} 与自定义数据集设计一起使用,您必须创建一个属于^{} 子类的数据集类(并实现特定函数)并将其传递给dataloader,即使他们这样说:
这是发生在:
如果你检查他们的^{} ,你会发现他们是这样做的。在
有几种可能的方法:
要从数据集中只获取批处理,可以执行以下操作:
^{pr2}$要访问整个数据集(尤其是在您的示例中):
(
.records
是可能因数据集而异的部分,我说.records
,因为这是我在{a4}中发现的)相关问题 更多 >
编程相关推荐