batch_size的探索

简介: batch_size的探索

问题

test_loader 中的y 表示每一个batch对应的128张图片对应的数字,torch.Size([256])表示什么意思?


方法

在打印了X的长度之后,发现X的长度也为256,这表示此处用作测试的X是由256个1x28x28的矩阵构成的多元组矩阵集合。也即,y的长度为256,而不是128。

for X, y in test_loader:  
    print(X.shape, y.shape)
    print(y)
    print(len(X))
print(X)
原因:
在初次设置test_loader的batch_size为256,而不是128.

结语

在本次探索中,通过print(),我对test_loader中的(X, y)的数据格式有了一定的认识,同时对batch_size的重要性有了一定的了解。

目录
打赏
0
0
0
0
14
分享
相关文章
|
11月前
【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l
【Simulink】报错:Size mismatch (size [2 x 1] ~= size [1 x 1]). The size to the left is the size of the l
【Pytorch】Expected hidden[0] size (2, 136, 256), got [2, 256, 256]
文章解决了PyTorch中LSTM模型因输入数据的批次大小不一致导致的“Expected hidden[0] size”错误,并提供了两种解决方案:调整批次大小或在DataLoader中设置drop_last=True来丢弃最后一个不足批次大小的数据。
155 1
神经网络epoch、batch、batch size、step与iteration的具体含义介绍
神经网络epoch、batch、batch size、step与iteration的具体含义介绍
524 1
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
The size of tensor a (4) must match the size of tensor b (3) at non-singletonThe size of
1357 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
1032 0
神经网络的面试题--什么是Batch Size?为什么需要Batch Size
网传神经网络面试题什么是Batch Size?为什么需要Batch Size,先记录下来以备不时之需
517 0