我試圖合併keras中的2個順序模型。下面是代碼:在Keras中合併2個順序模型
model1 = Sequential(layers=[
# input layers and convolutional layers
Conv1D(128, kernel_size=12, strides=4, padding='valid', activation='relu', input_shape=input_shape),
MaxPooling1D(pool_size=6),
Conv1D(256, kernel_size=12, strides=4, padding='valid', activation='relu'),
MaxPooling1D(pool_size=6),
Dropout(.5),
])
model2 = Sequential(layers=[
# input layers and convolutional layers
Conv1D(128, kernel_size=20, strides=5, padding='valid', activation='relu', input_shape=input_shape),
MaxPooling1D(pool_size=5),
Conv1D(256, kernel_size=20, strides=5, padding='valid', activation='relu'),
MaxPooling1D(pool_size=5),
Dropout(.5),
])
model = merge([model1, model2], mode = 'sum')
Flatten(),
Dense(256, activation='relu'),
Dropout(.5),
Dense(128, activation='relu'),
Dropout(.35),
# output layer
Dense(5, activation='softmax')
return model
以下是錯誤日誌:
File "/nics/d/home/dsawant/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 392, in is_keras_tensor raise ValueError('Unexpectedly found an instance of type
' + str(type(x)) + '
. ' ValueError: Unexpectedly found an instance of type<class 'keras.models.Sequential'>
. Expected a symbolic tensor instance.
一些更多的日誌:
ValueError: Layer merge_1 was called with an input that isn't a symbolic tensor. Received type: class 'keras.models.Sequential'. Full input: [keras.models.Sequential object at 0x2b32d518a780, keras.models.Sequential object at 0x2b32d521ee80]. All inputs to the layer should be tensors.
我如何可以合併使用不同的窗口大小這2個連續的模型和像'最大','總和'等功能應用於他們?
您需要合併兩個模型的輸出層,我不認爲您可以合併keras中的編譯模型。你應該看看[keras的功能API](https://keras.io/getting-started/functional-api-guide/) – gionni
檢查:https://stackoverflow.com/questions/44872982/how-do-i -train-multiple-neural-nets-in-keras –
明白了。我認爲我們可以。這值得一試。感謝您的鏈接 –