我有Keras模型
nodes_1_layer=200
def build_model():
activation=tf.nn.leaky_relu
model = keras.Sequential([
layers.Dense(nodes_1_layer, activation=tf.nn.relu, input_shape=[len(data_train.keys())]),
layers.Dense(nodes_1_layer, activation=activation),
layers.Dense(nodes_1_layer, activation=activation),
layers.Dense(nodes_1_layer, activation=activation),
layers.Dense(nodes_1_layer, activation=activation),
layers.Dense(1)
])
optimizer = tf.train.AdamOptimizer(learning_rate)
model.compile(loss='mse',optimizer=optimizer,metrics=['mae', 'mse'])
return model
model = build_model()
history_5= model.fit(data_train,train_labels,epochs=EPOCHS, validation_split = validation_split, verbose=0,callbacks=[PrintDot()])
hist_5= pd.DataFrame(history_5.history)
hist_5['epoch'] = history_5.epoch
hist_5.tail()
loss_cal_AB, mae_AB, mse_AB = model.evaluate(data_AB_eval, eval_AB_labels, verbose=0)
,我想获得输出相对于输入的派生。
先前的答案表明,我应该使用类似的东西
grads=K.gradients(model.output, model.input)
session=K.get_session()
我从中得到的是一个列表,我认为该列表包含符号派生词。如何使用我的数据评估这些梯度以获得浮点数(numpy-)?