keras theano中的负维度是什么意思

what is the meaning of negative dimension in keras theano

我已经尝试定义一个简单的架构以用于 MNIST 数据集,我开始这样定义我的架构:

model = Sequential()

model.add(Convolution2D(32,(3,3),activation='relu',input_shape = (1,28,28)));

在这一步中,我检查了我的网络:

model.output_shape

它给了我这个:

(None, -1, 26, 32)

谁能给我解释一下负维度 (-1) 是什么意思?

虽然直接使用张量时 -1 实际上可能是未知大小,但 Keras 层不是这样工作的。 Keras 中的未知批量大小是 None 维度。

对于卷积,Keras 使用 channels_last 作为数据格式,因此您应该将数据整形为 (28,28,1),即 (imageSide1, imageSide2, channels)

通过将数据整形为 (1,28,28),卷积会认为第一个图像边是 1 个像素。并通过操作删除 2 个像素,结果将是 -1。因此,将其整形为 (28,28,1) 以获得 (None,26,26,32).

的输出

或者,您可以将卷积层中的 data_format 参数设置为 channels_first,或者甚至更改 keras.json 文件以将 channels_first 作为默认值。