Closed mahesh-infrrd closed 5 years ago
Had the same issue with MobileNet.
My solution is to save and reload the model yourself, which is what apply_modifications
does. In the load_model
step, you can use your custom_objects
.
# modify model, here swapping softmax for linear activation
model.layers[-1].activation = activations.linear
# save model to a temp file
model.save('temp.h5')
# reload model with `custom_objects`
model = load_model('temp.h5', custom_objects={'relu6': relu6, 'DepthwiseConv2D': DepthwiseConv2D})
# maybe remove the temp file
@wdeback the visualize_saliency is giving error due to the custom layer. Any solutions?
@saksham15082 I ran into the same problem, visualize_saliency of mobilenet, with guided backprop_modifier.
Solution:
from keras.utils import CustomObjectScope
with CustomObjectScope({'relu6': relu6}):
grads = visualize_saliency(model, layer_idx, filter_indices=class_idx, seed_input=inp, backprop_modifier='guided')
@maor121 's solution is so smart.
I believe this issue is resolved. If there is still the problem, feel free to reopen this issue.
I'm using Keras 2.0.6 and have trained a model based on the Inception-V3 architecture with custom objects for metrics. As it is mentioned in the Keras documentation, the custom objects need to be used in
load_model
method. But in Keras-Vis theapply_modifications
method only accepts the model, not the custom objects after swapping the activation layers.model = utils.apply_modifications(model)
ValueError: Unknown metric function:precision