【发布时间】:2017-10-31 12:24:55
【问题描述】:
我有两种不同类型的数据(图像体积和坐标),我想在图像体积数据上使用卷积神经网络,然后在此之后我想附加一些附加信息(即图像的坐标)量)。
独立地,这应该为我的函数创建一个非常可靠的预测器。我如何使用 Keras 来实现这一点。
我在网上找到的唯一答案要么模棱两可,要么使用了我必须使用的已弃用的方法。但是我真的很想使用当前的 API 来实现它,这样我可以更轻松地保存模型以供以后使用。
model = Sequential()
model.add(Conv3D(32, kernel_size=(3, 3, 3),
activation='relu',
input_shape=input_shape))
model.add(Conv3D(64, (3, 3, 3), activation='relu'))
model.add(MaxPooling3D(pool_size=(2, 2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
print(model.output_shape)
# The additional data (the coordinates x,y,z)
extra = Sequential()
extra.add(Activation('sigmoid', input_shape=(3,)))
print(extra.output_shape)
merged = Concatenate([model, extra])
# New model should encompass the outputs of the convolutional network and the coordinates that have been merged.
# But how?
new_model = Sequential()
new_model.add(Dense(128, activation='relu'))
new_model.add(Dropout(0.8))
new_model.add(Dense(32, activation='sigmoid'))
new_model.add(Dense(num_classes, activation='softmax'))
new_model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
【问题讨论】:
标签: python deep-learning keras