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的重要性有了一定的了解。

目录
相关文章
|
9月前
【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
|
6月前
|
机器学习/深度学习 PyTorch 算法框架/工具
【Pytorch】Expected hidden[0] size (2, 136, 256), got [2, 256, 256]
文章解决了PyTorch中LSTM模型因输入数据的批次大小不一致导致的“Expected hidden[0] size”错误,并提供了两种解决方案:调整批次大小或在DataLoader中设置drop_last=True来丢弃最后一个不足批次大小的数据。
126 1
|
移动开发 安全 JavaScript
MAX4/11/03/016/08/1/1/00 MAX-4/11/01/008/08/1/1/00
MAX4/11/03/016/08/1/1/00 MAX-4/11/01/008/08/1/1/00
64 0
|
机器学习/深度学习 算法 算法框架/工具
深度学习中epoch、batch、batch size和iterations详解
深度学习中epoch、batch、batch size和iterations详解
592 0
|
9月前
|
机器学习/深度学习 算法 定位技术
神经网络epoch、batch、batch size、step与iteration的具体含义介绍
神经网络epoch、batch、batch size、step与iteration的具体含义介绍
466 1
C400/A8/1/1/1/00 MAX-4/11/03/128/99/1/0/00
C400/A8/1/1/1/00 MAX-4/11/03/128/99/1/0/00
48 0
|
数据格式
详解torch.size
详解torch.size
269 0
详解torch.size
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
1251 0
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
986 0
|
机器学习/深度学习
神经网络的面试题--什么是Batch Size?为什么需要Batch Size
网传神经网络面试题什么是Batch Size?为什么需要Batch Size,先记录下来以备不时之需
495 0