tf.keras.backend.stop_gradient(variables)

Returns variables but with zero gradient w.r.t. every other variable.
• variables: Tensor or list of tensors to consider constant with respect to any other variable.