首页 文章

使用Keras通过简单回归获得形状尺寸误差

提问于
浏览
0

我正在尝试在Keras上训练一个简单的回归网络 . 网络的输入(X_test)是100个图像,输出另外100个 . 问题是我得到一个形状错误:我玩过另一个网络架构,激活,......并且错误仍然存在 .

在这里我放置我的代码:

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做回归,我不知道我做错了什么 .

感谢您的时间!

1 回答

  • 0

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

相关问题