Open jashshah opened 5 years ago
Hi, @jashshah .
The problem seems to be caused by tf.keras
or something else.
At least, I believe keras-vis don't have the cause of the problem,
because utils.apply_modifications(model)
just call keras.models.Model.save()
and keras.models.load_model()
internally.
I suggest you ask StackOverFlow or Tensorflow's community this problem.
try this line of code it worked for me:
with CustomObjectScope({'GlorotUniform': glorot_uniform()}): .............................................
I have the same problem
Try this code if you used a custom loss for training your model, it also worked for me:
from keras.utils import CustomObjectScope
from keras.initializers import glorot_uniform
from tensorflow.keras.models import load_model
def myLoss(y_true, y_pred):
...
return Something
model = load_model('yourModel.hdf5', custom_objects={'myLoss': myLoss, "GlorotUniform": tf.keras.initializers.glorot_uniform})
Query : can't use Keras-viz : from vis.visualization import visualize_cam There is a compatibility issue with scipy version. scipy.misc import imresize not available in colab
Solution : Check that you are up-to-date with the master branch of keras-vis. You can update with: pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
Above solution resolves my issue. Thanks.
I have the same problem on TensorFlow 1.14.0.
When I call
from tensorflow import keras
model = utils.apply_modifications(model)
ValueError: Unknown initializer: GlorotUniform
I get a different second error... when I call
model = utils.apply_modifications(model, custom_objects={"GlorotUniform": keras.initializers.glorot_uniform})
I get error
TypeError: Unexpected keyword argument passed to optimizer: name
I also get a different error when from
import keras
TypeError: glorot_uniform() got an unexpected keyword argument 'dtype'
I suspect the problem is... I am using tensorflow's version of keras
from tensorflow import keras
Whereas... this utils.py in keras-viz is using the keras library directly
from keras.models import load_model
Perhaps there is a mismatch between the two versions.
Installing TensorFlow version 2.0 and passing the custom objects solved the issue for me.
from tensorflow.python.keras.models import load_model
model = load_model('model.h5',custom_objects={"adam": tf.keras.optimizers.Adam,
"mae":tf.keras.losses.mean_absolute_error})
Installing TensorFlow version 2.0 and passing the custom objects solved the issue for me.
Does this package support TF 2.0? When I run with TF 2.0, I get:
module 'tensorflow' has no attribute 'placeholder'
I'm trying to use the library with Tensorflow 1.14 using tf.keras, however if I install it with pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
I get an error saying that the keras module has not been found. That's expected.
Instead, if I install it with
pip install git+git://github.com/raghakot/keras-vis.git --upgrade
I get TypeError: tuple indices must be integers or slices, not list
when I run model = utils.apply_modifications(model)
[Edit] I have ported the library to tf.keras here https://github.com/alessandro-montanari/keras-vis/tree/tf-keras-support It seems to be working but has not been tested deeply yet.
Sorry for inconvenience. We've NOT been working for support Tensorflow 2.0 yet. For now, you guys can use alternative library that I developed for my own experiments. Would you please try it if it's okay.
Hey,
I'm getting one of two errors: Error 1:
(gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error: "Failed to load model: Unexpected error when loading the model: Unexpected keyword argument passed to optimizer: learning_rate (Error code: 0)"
Error 2:
(gcloud.beta.ai-platform.versions.create) Create Version failed. Bad model detected with error: "Failed to load model: Unexpected error when loading the model: Unexpected keyword argument passed to optimizer: name (Error code: 0)"
(the only diff in the above to errors is that one complains about learning rate, and the other complains about name)
both errors pop up even though I have made no code changes. I am trying to publish a model onto the ai-platform following this guide exactly: https://cloud.google.com/ml-engine/docs/tensorflow/custom-prediction-routine-keras
I've tried the custom_objects every way I think possible. Does anyone know a solution?
I'm trying to use the library with Tensorflow 1.14 using tf.keras, however if I install it with
pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
I get an error saying that the keras module has not been found. That's expected.Instead, if I install it with
pip install git+git://github.com/raghakot/keras-vis.git --upgrade
I getTypeError: tuple indices must be integers or slices, not list
when I runmodel = utils.apply_modifications(model)
[Edit] I have ported the library to tf.keras here https://github.com/alessandro-montanari/keras-vis/tree/tf-keras-support It seems to be working but has not been tested deeply yet.
I am getting same errror
try this line of code it worked for me:
with CustomObjectScope({'GlorotUniform': glorot_uniform()}): .............................................
When I do that I get:
TypeError: glorot_uniform() got an unexpected keyword argument 'dtype'
I am facing the same issue with Keras Vis.
ValueError: Unknown initializer: GlorotUniform
_model.layers[layer_index].activation = activations.linear model = utils.applymodifications(model)
I have tried all the possible approaches mentioned above. Also tried re-installing via pip install git+https://github.com/raghakot/keras-vis.git -U
Let me know if a solution is available for this.
I switched to tf explain.
[x] Check that you are up-to-date with the master branch of keras-vis. You can update with: pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
[x] If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
[x] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
[x] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
Hi,
Kudos to the work done with the library so far. However when using it with
tf.keras
I am facing the following error:ValueError: Unknown initializer: GlorotUniform
Here is the code I used to train the model:
Getting the cam visualizations:
Here is the error that I get:
And when I change the
utils.apply_modifications(model)
toutils.apply_modifications(model, custom_objects={"GlorotUniform": tf.keras.initializers.glorot_uniform})
I getUsing tensorflow 1.12.0
Any help will be appreciated.