LeNet接受32X32图像。因此,要将LeNet用于MNIST数据集,我们必须将大小从28X28更改为32X32。我偶然发现了这实现。我对下面这一行代码的工作方式感到困惑。
np.pad(X_train, ((0,0),(2,2),(2,2),(0,0)), 'constant')上面的代码pad 28X28像素图像变成了32X32图像。有人能帮我弄清楚到底是怎么做到的吗。
发布于 2018-09-17 13:15:47
基本上,它所做的正是您所指定的。用numpy函数在每个维度中追加值。给定数据集的维度,每个轴上的"pads“数量由((0,0),(2,2),(2,2),(0,0))指定,即:
10000 (samples) x 28 (image dimension 1) x 28 (image dim. 2) x 1 (grayscale value!)现在让我们看看您的规范在这方面意味着什么:
(0,0)Pad 0(as in the amount) values before and after each row
(2,2)Pad 2 before and 2 after each value of dim. 1 of your image data: 28 values -> 32
(2,2)Pad 2 before and 2 after each value of dim. 2 of your image data: 28 values -> 32
(0,0)Pad, again, nothing in the grayscale value dimension这意味着您将在相应的维度中得到一个32x32图像。现在,剩下的唯一的事情是:我们应该填充哪些值?答案很简单,您没有指定任何constant_values,这意味着它将使用默认的constant_values (在上面链接的页面上指定)。即这个值是0。
总之,简单地想象一下,你有一个32x32的图像,你的28x28在中间,在外面,你有一个0's的2值边框。
https://datascience.stackexchange.com/questions/38351
复制相似问题