当我检查张量形状时,火炬大小([64,1,28,28])中的1是什么意思?

2024-03-29 01:59:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我之所以关注this tutorial on towardsdatascience.com,是因为我想使用Pytorch尝试MNIST数据集,因为我已经使用keras完成了它

因此,在步骤2中,更好地了解数据集,他们打印火车装载机的形状,它返回torch.Size([64, 1, 28, 28])。我知道64是加载程序中的图像数,每个图像都是28x28图像,但1到底是什么意思


Tags: 数据图像comsizeon步骤torchpytorch
3条回答

这将表明数据集中存在的批次数。把它想象成一组,我们有一批64张图片,或者你可以改变它,比如说,每个有两批32张图片。批量大小通常会影响模型的计算复杂性。 当然,根据所使用的库(特别是在培训/测试循环中),如果只使用1批或X批,代码看起来会略有不同

例如(历元数/迭代次数=50):假设您正在训练批量大小为1的数据集,在训练循环中,您只需编写训练模型历元时间。但是,对于batch size=x,您必须为每个历元以及每个批次/组循环

简而言之,
这只是你的28x28图像的通道数

它是输入中的通道数。在MNIST数据集中,图像为灰度,因此图像的形状为[28, 28, 1]。请注意,pytorch将第一个维度设置为通道维度

当然,一旦作为批加载,总输入形状就是您得到的形状

请参阅MNIST dataset链接,其中指出:

The original black and white (bilevel) images from NIST were size normalized to fit in a 20x20 pixel box while preserving their aspect ratio. The resulting images contain grey levels as a result of the anti-aliasing technique used by the normalization algorithm. the images were centered in a 28x28 image by computing the center of mass of the pixels, and translating the image so as to position this point at the center of the 28x28 field.

相关问题 更多 >