1

我有一个问题是要弄清楚图像中是否存在特定的线条。作为输入 - 我有一个 96*54 的二进制图像,作为输出我有 18 个数字,1 或 0。

当我尝试创建多个输出时,拟合后出现以下错误:模型需要 18 个目标数组,但只收到一个数组。我尝试以多种方式尝试重塑输出张量,甚至使用 python 数组来保存 np 张量,但没有成功。

这是代码:

main_input = Input(shape=(54,96,1))
x = Conv2D(16,kernel_size=(3,3),activation='relu')(main_input)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Conv2D(32,kernel_size=(3,3),activation='relu')(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Conv2D(64,(3,3),activation='relu')(x)
x = MaxPooling2D(pool_size=(2,2))(x)
x = Conv2D(128,(3,3),activation='relu')(x)
x = Flatten()(x)
x = Dense(256,activation='relu')(x)
out = [Dense(1,activation='softmax')(x)] * 18
y_train_split = np.asarray([y_train[:,i] for i in range(18)])

model = Model(inputs=main_input, outputs=out)
model.compile(loss=keras.losses.binary_crossentropy, optimizer=keras.optimizers.Adadelta(),metrics=['accuracy'])
model.fit(x_train, y_train_split, batch_size=batch_size, epochs=epochs,verbose=1,validation_data = (x_test,y_test))
score = model.evaluate(x_eval,y_eval,verbose=0)
4

0 回答 0