[英]input_shape 2D Convolutional layer in keras
In the Keras Documentation for Convolution2D
the input_shape
a 128x128 RGB pictures is given by input_shape=(3, 128, 128)
, thus I figured the first component should be the number of planes (or feature layers). 在Keras的文档Convolution2D
的input_shape
一个128×128的RGB图像由下式给出input_shape=(3, 128, 128)
因而我计算第一组分应该是平面(或特征的层)的数量。
If I run the following code: 如果我运行以下代码:
model = Sequential()
model.add(Convolution2D(4, 5,5, border_mode='same', input_shape=(3, 19, 19), activation='relu'))
print(model.output_shape)
I get an output_shape
of (None, 3, 19, 4)
, whereas in my understanding this should be (None, 4, 19, 19)
with 4 the number of filters. 我得到一个(None, 3, 19, 4)
output_shape
,而在我的理解中,这应该是(None, 4, 19, 19)
output_shape
(None, 3, 19, 4)
,其中4个是过滤器的数量。
Is this an error in the example from the keras documentation or am I missing something? 这是来自keras文档的示例中的错误还是我遗漏了什么?
(I am trying to recreate a part of AlphaGo so the 19x19 is the board size which would correspond to the images size. ) (我正在尝试重新创建AlphaGo的一部分,因此19x19是与图像大小相对应的电路板尺寸。)
You are using the Theano dimension ordering (channels, rows, cols)
as input but your Keras seems to use the Tensorflow one which is (rows, cols, channels)
. 您使用Theano维度排序(channels, rows, cols)
作为输入,但您的Keras似乎使用Tensorflow (rows, cols, channels)
。
So either you can switch to the Theano dimension ordering, directly in your code with : 因此,您可以直接在代码中切换到Theano维度排序:
import keras.backend as K K.set_image_dim_ordering('th')
Or editing the keras.json
file in (usually in ~\\.keras
) and switching 或者编辑keras.json
文件(通常在~\\.keras
)并切换
"image_dim_ordering": "tf"
to "image_dim_ordering": "th"
"image_dim_ordering": "tf"
到"image_dim_ordering": "th"
Or you can keep the Tensorflow dimension ordering and switch your input_shape
to (19,19,3)
或者您可以保持Tensorflow维度排序并将input_shape
切换为(19,19,3)
Yes it should be (None, 4, 19, 19). 是的,它应该是(无,4,19,19)。 There is something called dim_ordering
in keras that decides in which index should one place the number of input channels
. 在keras中有一个叫做dim_ordering
东西决定了哪个索引应该放置number of input channels
的number of input channels
。 Check the documentation of "dim_ordering" parameter in the documentation . 请查看文档中“dim_ordering”参数的文档 。 Mine is set to 'tf'. 我的设置为'tf'。
So; 所以; just change the input shape
to (19, 19, 3)
like so 只需将input shape
更改为(19, 19, 3)
model.add(Convolution2D(4, 5,5, border_mode='same', input_shape=(19, 19,3), activation='relu'))
Then check the output shape. 然后检查输出形状。
You can also modify the dim_ordering
in the file usually at ~/.keras/keras.json
to your liking 您还可以修改dim_ordering
文件中通常在~/.keras/keras.json
根据自己的喜好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.