使用 Keras 通过简单回归获取形状尺寸错误
Getting shape dimension errors with a simple regression using Keras
我正在尝试在 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 中做回归,我不知道我做错了什么。
感谢您的宝贵时间!
模型的输出形状为 (None, 256, 7, 7)。那应该与 y_train 的形状匹配。要获得形状 (None, 3, 32, 32),您需要更改架构,可能是通过添加上采样层。例如,参见 https://blog.keras.io/building-autoencoders-in-keras.html。
我正在尝试在 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 中做回归,我不知道我做错了什么。
感谢您的宝贵时间!
模型的输出形状为 (None, 256, 7, 7)。那应该与 y_train 的形状匹配。要获得形状 (None, 3, 32, 32),您需要更改架构,可能是通过添加上采样层。例如,参见 https://blog.keras.io/building-autoencoders-in-keras.html。