简体   繁体   English

如何在 pytorch 的 DataLoader 中查看数据

[英]how to see the data in DataLoader in pytorch

I see something like the following in the examples on Github.我在 Github 的示例中看到类似以下内容。 How can I see the type of this data (shape and the other properties)?如何查看此数据的类型(形状和其他属性)?

train_data = MyDataset(int(1e3), length=50)
train_iterator = DataLoader(train_data, batch_size=1000, shuffle=True)

You can inspect the data with following statements:您可以使用以下语句检查数据:

data = train_iterator.dataset.data 
shape = train_iterator.dataset.data.shape  
datatype = train_iterator.dataset.data.dtype

You can iterate the data and feed to a network as:您可以迭代数据并将其馈送到网络,如下所示:

for nth_batch, (batch,_) in enumerate(train_iterator):
    feedable = Variable(batch)
    #here goes neural nets part

As Ivan stated in comments Variable is deprecated (although it still works fine) and Tensor itself now supports autograd, so the batch can be used in neural net.正如 Ivan 在评论中所说,不推荐使用变量(尽管它仍然可以正常工作),并且 Tensor 本身现在支持 autograd,因此批处理可以在神经网络中使用。

for nth_batch, (batch,_) in enumerate(train_iterator):
    #feedforward the batch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM