事實上,正如@Marcin所說,你可以使用合併層。
我建議你爲此使用Functionnal API。如果您不熟悉它,請閱讀some doc here。
下面是使用keras API您亂畫網絡模式:
from keras.layers.core import *
from keras.models import Model
# this is your image input definition. You have to specify a shape.
image_input = Input(shape=(32,32,3))
# Some more data input with 10 features (eg.)
other_data_input = Input(shape=(10,))
# First convolution filled with random parameters for the example
conv1 = Convolution2D(nb_filter = nb_filter1, nb_row = nb_row1, nb_col=_nb_col1, padding = "same", activation = "tanh")(image_input)
# MaxPool it
conv1 = MaxPooling2D(pool_size=(pool_1,pool_2))(conv1)
# Second Convolution
conv2 = Convolution2D(nb_filter = nb_filter2, nb_row = nb_row2, nb_col=_nb_col2, padding = "same", activation = "tanh")(conv1)
# MaxPool it
conv2 = MaxPooling2D(pool_size=(pool_1,pool_2))(conv2)
# Flatten the output to enable the merge to happen with the other input
first_part_output = Flatten()(conv2)
# Merge the output of the convNet with your added features by concatenation
merged_model = keras.layers.concatenate([first_part_output, other_data_input])
# Predict on the output (say you want a binary classification)
predictions = Dense(1, activation ='sigmoid')(merged_model)
# Now create the model
model = Model(inputs=[image_input, other_data_input], outputs=predictions)
# see your model
model.summary()
# compile it
model.compile(optimizer='adamax', loss='binary_crossentropy')
你去那裏:)這到底是很容易的,定義要多少投入和產出,只需指定它們在列表中當您創建Model
對象時。當你適應它時,也將它們單獨送入列表中。
您正在嘗試構建的架構是什麼?我不確定要理解你的問題 –
@NassimBen現在我已經添加了所需的架構! :) –