简体   繁体   English

keras 输入形状混淆

[英]keras input shape confusion

Hi I have images with the size of 160*120 (meaning 160 is the width and 120 is the height) I want to train a network with this data set in keras and no resizing.. I think in keras instead of writing嗨,我有大小为 160*120 的图像(意思是 160 是宽度,120 是高度)我想用 keras 中的这个数据集训练一个网络并且没有调整大小..我认为在 keras 中而不是写作

model.add(Conv2D(....,input_shape = (160,120,1) , ....)

I should write我应该写

model.add(Conv2D(....,input_shape = (120,160,1) , ....)

so does input shape in keras first take height and then width?though with both input sizes the training starts and no error pops up indicating that input size doesn't match... One other note is that after training the network with那么 keras 中的输入形状是否首先取高度,然后取宽度?尽管使用两种输入大小开始训练,并且没有弹出错误表明输入大小不匹配......另一个注意事项是在训练网络后

model.add(Conv2D(....,input_shape = (120,160,1) , ....)

as my input shape still in summary it says Output Shape = (None,159,119,3) after the first convolution layer with filter size=2*2 and number of filters being 3...I thought it should be Output Shape = (None,119,159,3) I am really confused can anyone help?作为我的输入形状仍然总结它说输出形状=(无,159,119,3)在第一个卷积层之后,过滤器大小= 2 * 2,过滤器数量为3......我认为它应该是输出形状=(无,119,159,3) 我真的很困惑有人可以帮忙吗?

From the TensorFlow docs :来自TensorFlow 文档

Input shape: 4+D tensor with shape: batch_shape + (channels, rows, cols) if data_format='channels_first' or 4+D tensor with shape: batch_shape + (rows, cols, channels) if data_format='channels_last'.输入形状:4+D 张量,形状:batch_shape + (channels, rows, cols) if data_format='channels_first' 或 4+D 张量,形状:batch_shape + (rows, cols, channels) if data_format='channels_last'。

A 160 pixel width means 160 columns and a 120 pixel height means 120 rows, so the correct Tensor input_shape would be (120, 160, 1) for your 1-channel image. 160 像素宽度表示 160 列,120 像素高度表示 120 行,因此对于 1 通道图像,正确的 Tensor input_shape将为(120, 160, 1)

Using 3 filters in your Conv2D layer means that three individual kernels convolve (slide) over your input image.Conv2D层中使用 3 个过滤器意味着三个单独的内核在您的输入图像上进行卷积(滑动)。 With a 2x2 kernel size, it means that your Conv2D layer will produce 3 outputs of size (input_width-1, input_height-1) , which indeed is (159, 119, 3) in your case.使用 2x2 内核大小,这意味着您的Conv2D层将产生 3 个大小为(input_width-1, input_height-1) ,在您的情况下确实是(159, 119, 3)

来源:https://www.machinecurve.com/index.php/2021/11/07/introduction-to-isotropic-architectures-in-computer-vision/ (source: https://www.machinecurve.com/index.php/2021/11/07/introduction-to-isotropic-architectures-in-computer-vision/ ) (来源: https : //www.machinecurve.com/index.php/2021/11/07/introduction-to-isotropic-architectures-in-computer-vision/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM