使用Keras通过简单的回归获得形状尺寸误差 [英] Getting shape dimension errors with a simple regression using Keras

查看:155
本文介绍了使用Keras通过简单的回归获得形状尺寸误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Keras上训练一个简单的回归网络.网络的输入(X_test)是100张图像,输出的是另外100张图像.问题是我遇到形状错误:我在玩另一种网络体系结构,激活...,并且该错误仍然存​​在. /p>

我在这里放置我的代码:

M=32

input_layer         = Input(shape=(3, 32, 32), name="input")

sc1_conv1           = Convolution2D(96, 3, 3, activation='relu', init='glorot_uniform', subsample=(2,2), border_mode='valid')(input_layer)

sc1_maxpool1        = MaxPooling2D(pool_size=(2,2))(sc1_conv1)

sc1_fire2_squeeze   = Convolution2D(M, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_maxpool1)
sc1_fire2_expand1   = Convolution2D(M*4, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_fire2_expand2   = Convolution2D(M*4, 3, 3, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_merge1          = merge(inputs=[sc1_fire2_expand1, sc1_fire2_expand2], mode="concat", concat_axis=1)
sc1_fire2           = Activation("linear")(sc1_merge1)

model               = Model(input=input_layer, output=sc1_fire2)
model.compile(loss='mse', optimizer='rmsprop')
model.fit(X_train, y_train, nb_epoch=10, batch_size=64)

运行脚本时,出现以下错误:

Exception: Error when checking model target: expected activation_9 to have shape (None, 256, 7, 7) but got array with shape (100, 3, 32, 32)

X_train和y_train形状为:

X_train.shape
Out[13]: (100, 3, 32, 32)
y_train.shape
Out[14]: (100, 3, 32, 32)

这是我第一次在Keras中进行回归,我不知道自己做错了什么.

谢谢您的时间!

解决方案

模型的输出形状为(None,256,7,7).那应该与y_train的形状匹配.要获得形状(无,3、32、32),您可能需要更改架构,可能需要添加上采样层.请参阅 https://blog.keras.io/building-autoencoders-in-keras. html .

I am trying to train a simple regression network on Keras. The input of the network (X_test) are 100 images, and the output another 100. The problem is that I am getting a shape error: I have played with another network architecture, activations,... and the error is still there.

Here I place my code:

M=32

input_layer         = Input(shape=(3, 32, 32), name="input")

sc1_conv1           = Convolution2D(96, 3, 3, activation='relu', init='glorot_uniform', subsample=(2,2), border_mode='valid')(input_layer)

sc1_maxpool1        = MaxPooling2D(pool_size=(2,2))(sc1_conv1)

sc1_fire2_squeeze   = Convolution2D(M, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_maxpool1)
sc1_fire2_expand1   = Convolution2D(M*4, 1, 1, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_fire2_expand2   = Convolution2D(M*4, 3, 3, activation='relu', init='glorot_uniform', border_mode='same')(sc1_fire2_squeeze)
sc1_merge1          = merge(inputs=[sc1_fire2_expand1, sc1_fire2_expand2], mode="concat", concat_axis=1)
sc1_fire2           = Activation("linear")(sc1_merge1)

model               = Model(input=input_layer, output=sc1_fire2)
model.compile(loss='mse', optimizer='rmsprop')
model.fit(X_train, y_train, nb_epoch=10, batch_size=64)

When I run the script, I get the following error:

Exception: Error when checking model target: expected activation_9 to have shape (None, 256, 7, 7) but got array with shape (100, 3, 32, 32)

The X_train and y_train shapes are:

X_train.shape
Out[13]: (100, 3, 32, 32)
y_train.shape
Out[14]: (100, 3, 32, 32)

It is my first time doing regression in Keras and I don't know what I am doing wrong.

Thank you for your time!

解决方案

The output shape of your model is (None, 256, 7, 7). That should match with the shape of y_train. To get the shape (None, 3, 32, 32), you'd need to change your architecture, possibly by adding upsampling layers. See https://blog.keras.io/building-autoencoders-in-keras.html for example.

这篇关于使用Keras通过简单的回归获得形状尺寸误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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