Can't import plot_model from keras.utils?

Viewed 32888

When I run this line in my code,

from keras.utils import plot_model

I get the following:

"ImportError: cannot import name 'plot_model' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)"

When I went to bed last night it was working. This morning it throws an error. What happened and what should I do? Thank you. Any suggestion would be appreciated

4 Answers

Try to import in the below format

from keras.utils.vis_utils import plot_model

This week I've had the same problem, with this import it works.

This worked taking from TensorFlow documentation

from keras.utils.vis_utils import plot_model
tf.keras.utils.plot_model(
model, to_file='model.png', show_shapes=False, show_dtype=False,
show_layer_names=True, rankdir='TB', expand_nested=False, dpi=96
)

In the recent version of keras, plot_model function has been moved to vis_utils (visualization utilities) under the utils module. So, you can get your plot_model function to work using either of these imports:

from keras.utils.vis_utils import plot_model

or

from tensorflow.keras.utils import plot_model
from keras.utils.vis_utils import plot_model

The plot_model was previously in Keras.utils, but it can be fetched from vis.utils Copy paste the above code, and it will work

Related