tf.keras.backend.learning_phase()
The learning phase flag is a bool tensor (0 = test, 1 = train) to be passed as input to any Keras function that uses a different behavior at train time and test time.
tf.keras.backend.learning_phase_scope(value)
The learning phase gets restored to its original value upon exiting the scope.
value
: Learning phase value, either 0 or 1 (integers). 0 = test, 1 = train
tf.keras.backend.learning_phase()
返回当前状态flag,是train还是test阶段
tf.keras.backend.learning_phase_scope(value)
将当前scope下的代码运行于train(value=1
)或test(value=0
)状态下
with keras.backend.learning_phase_scope(1):
y_probas = np.stack([model.predict(X_test_scaled) for sample in range(100)])