Keras可以处理不同大小的输入图像吗? [英] Can Keras deal with input images with different size?

查看:828
本文介绍了Keras可以处理不同大小的输入图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Keras可以处理不同大小的输入图像吗?例如,在全卷积神经网络中,输入图像可以具有任何大小.但是,在使用Keras创建网络时,需要指定输入形状.因此,如何在不将输入图像调整为相同大小的情况下使用Keras处理不同的输入大小?感谢您的帮助.

Can the Keras deal with input images with different size? For example, in the fully convolutional neural network, the input images can have any size. However, we need to specify the input shape when we create a network by Keras. Therefore, how can we use Keras to deal with different input size without resizing the input images to the same size? Thanks for any help.

推荐答案

是. 只需将输入形状更改为shape = {n_channels,). 其中n_channels是您输入图像中的频道数.

Yes. Just change your input shape to shape=(n_channels, None, None). Where n_channels is the number of channels in your input image.

我正在使用Theano后端,因此,如果您使用的是张量流,则可能必须将其更改为(None,None,n_channels)

I'm using Theano backend though, so if you are using tensorflow you might have to change it to (None,None,n_channels)

您应该使用:

You should use:

input_shape =(1,无,无)

input_shape=(1, None, None)

形状中没有一个表示可变尺寸.请注意,并非所有图层 可以使用这样的可变尺寸,因为某些图层需要 形状信息(例如展平). https://github.com/fchollet/keras/issues/1920

None in a shape denotes a variable dimension. Note that not all layers will work with such variable dimensions, since some layers require shape information (such as Flatten). https://github.com/fchollet/keras/issues/1920

例如,使用keras的功能性API,您的输入层将是:

For example, using keras's functional API your input layer would be:

对于RGB数据集

inp = Input(shape=(3,None,None))

对于灰色数据集

inp = Input(shape=(1,None,None))

这篇关于Keras可以处理不同大小的输入图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆