def modify_model_backprop(model, backprop_modifier):
<EOL>modified_model = _MODIFIED_MODEL_CACHE.get((model, backprop_modifier))<EOL>if modified_model is not None:<EOL><INDENT>return modified_model<EOL><DEDENT>model_path = os.path.join(tempfile.gettempdir(), next(tempfile._get_candidate_names()) + '<STR_LIT>')<EOL>try:<EOL><INDENT>model.save(model_path)<EOL>modifier_fn = _BACKPROP_MODIFIERS.get(backprop_modifier)<EOL>if modifier_fn is None:<EOL><INDENT>raise ValueError("<STR_LIT>".format(backprop_modifier))<EOL><DEDENT>modifier_fn(backprop_modifier)<EOL>with tf.get_default_graph().gradient_override_map({'<STR_LIT>': backprop_modifier}):<EOL><INDENT>modified_model = load_model(model_path)<EOL>_MODIFIED_MODEL_CACHE[(model, backprop_modifier)] = modified_model<EOL>return modified_model<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>os.remove(model_path)<EOL><DEDENT>
Creates a copy of model by modifying all activations to use a custom op to modify the backprop behavior.

    Args:
        model:  The `keras.models.Model` instance.
        backprop_modifier: One of `{'guided', 'rectified'}`

    Returns:
        A copy of model with modified activations for backwards pass.