代码拉取完成,页面将自动刷新
from keras.layers import LSTM, Dense, Input, Concatenate
from keras.models import Sequential, Model
from keras.optimizers import RMSprop
from keras.callbacks import EarlyStopping, TensorBoard
import keras.backend as K
import numpy as np
def diff(y_true, y_pred):
if K.backend() == 'tensorflow':
import tensorflow as tf
return tf.abs(y_true - y_pred)
model = Sequential(name='Model')
model.add(LSTM(20, input_shape=[5, 5], return_sequences=True, dropout=0.2, recurrent_dropout=0.2))
model.add(LSTM(30, return_sequences=False))
model.add(Dense(3, activation='softmax'))
X = np.random.random((1000, 5, 5))
y = np.zeros((1000, 3))
# model.summary()
model.compile(RMSprop(), loss='categorical_crossentropy', metrics=['acc'])
# history = model.fit(X, y, verbose=2, batch_size=5, epochs=10, callbacks=[EarlyStopping(monitor='loss', patience=2, verbose=1), TensorBoard()])
inp1 = Input((5, 5))
inp2 = Input((5, 5))
lstm1 = LSTM(20, dropout=0.1, return_sequences=False)
out1 = lstm1(inp1)
lstm2 = LSTM(30, dropout=0.1, return_sequences=False)
out2 = lstm2(inp2)
merged = Concatenate()([out1, out2])
dense = Dense(3, activation='softmax')
out = dense(merged)
model2 = Model(inputs=[inp1, inp2], outputs=[out])
model2.summary()
model2.compile(RMSprop(), loss=diff, metrics=['acc'])
history = model2.fit([X, X], y, verbose=2, batch_size=5, epochs=10, callbacks=[EarlyStopping(monitor='loss', patience=2, verbose=1), TensorBoard()])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。