【问题标题】:Pytorch tensor data is disturbed when I convert data loader tensor to numpy array当我将数据加载器张量转换为 numpy 数组时,Pytorch 张量数据受到干扰
【发布时间】:2020-02-29 18:39:36
【问题描述】:

我正在使用一个简单的训练循环来执行回归任务。为了确保回归的真实值与我在训练循环中的预期相同,我决定绘制每批数据。 但是,我看到当我将数据加载器的张量转换为 numpy 数组并绘制它时,它受到了干扰。我正在使用 myTensor.data.cpu().numpy() 进行转换。

我的代码如下:

train_ds = TensorDataset(x_train, y_train)
train_dl = DataLoader(train_ds, batch_size = 32, shuffle = True, num_workers = 0, drop_last = True)


for epoch in range(epochs):
  model.train()
for i, (x, y) in enumerate(train_dl):
  x = x.cuda()
  y = y.cuda()
  yy = y.data.cpu().numpy()
  pyplot.plot(yy[0: 32, 0])
  pyplot.show()

【问题讨论】:

    标签: python numpy pytorch dataloader


    【解决方案1】:

    我认为这是因为我在数据加载器中设置了 shuffle = True。 如果我将其设置为 false,那很好。但是,如果我在数据加载器中设置 shuffle = False 那么如何在每个 epoch 之后对训练批次进行混洗?

    【讨论】:

      猜你喜欢
      • 2019-06-13
      • 2018-09-20
      • 2019-04-27
      • 2018-10-22
      • 2021-10-17
      • 2018-11-28
      • 2021-04-28
      相关资源
      最近更新 更多