CNN和RNN的组合模型只能预测一个类别

时间:2019-05-31 12:50:46

标签: python recurrent-neural-network supervised-learning

我们已经将RNN和CNN模型组合在一起来预测类别。不幸的是,该模型只能预测一个具有相同值的类别。我们已经做了一些平衡。解决方案可能是什么?

inputCNN = tf.keras.Input(shape=(28, 28, 1))
CNN = tf.keras.layers.Conv2D(32, (3,3), activation='relu')(inputCNN)
CNN = tf.keras.layers.MaxPooling2D(2,2)(CNN)
CNN = tf.keras.layers.Conv2D(64, (3,3), activation='relu')(CNN)
CNN = tf.keras.layers.MaxPooling2D(2,2)(CNN)
CNN = tf.keras.layers.Conv2D(64, (3,3), activation='relu')(CNN)
CNN = tf.keras.layers.Flatten()(CNN)
CNN = tf.keras.layers.Dense(10, activation='softmax')(CNN)
modelCNN = tf.keras.Model(inputs=inputCNN, outputs=CNN)

inputRNN = tf.keras.Input(shape=(93,13))
RNN = tf.keras.layers.LSTM(128,return_sequences=True)(inputRNN)
RNN = tf.keras.layers.Dropout(0.2)(RNN)
RNN = tf.keras.layers.LSTM(128)(RNN)
RNN = tf.keras.layers.Dropout(0.2)(RNN)
RNN = tf.keras.layers.Dense(10, activation='softmax')(RNN)
modelRNN = tf.keras.Model(inputs=inputRNN, outputs=RNN)

combined = tf.keras.layers.concatenate([modelRNN.output, modelCNN.output])

final_dense = tf.keras.layers.Dense(10, activation='relu')(combined) #ff kijken of dit slim is
final_dense = tf.keras.layers.Dense(1, activation='sigmoid')(final_dense)

final_model = tf.keras.Model(inputs=[modelCNN.input, modelRNN.input], outputs=final_dense)

np.asarray(match_trainconverted).astype('float32').reshape((-1,1))

final_model.compile(optimizer='adam',
                    loss='binary_crossentropy',
                    metrics=['accuracy'])

final_model.fit([MNIST_traincopy, RNN_traincopy], array, epochs=1, batch_size=100)

0 个答案:

没有答案