from google.colab import drive
drive.mount('/content/drive')
!pip install tensorflow==2.6.4
import tensorflow as tf
print(tf.__version__)
pip install pydotplus
pip install graphviz
!git clone https://github.com/ryuuzaki42/plot_model
execfile("/content/plot_model/plot_model/plot_model.py")
plot_model(model)
# Default
#plot_model(model, to_file='model.png', show_shapes=True, show_layer_names=False, rankdir='TB', expand_nested=False, style=0, color=True, dpi=96)
# My use
#num_file = "01"
#file_name_s = "model_" + num_file + "_s.png"
#plot_model(model, to_file=file_name_s, show_shapes=False, show_layer_names=False, rankdir='TB', expand_nested=False, style=0, color=True, dpi=96)
model: A Keras model instance
to_file: File name of the plot image.
show_shapes: whether to display shape information.
show_dtype: whether to display layer dtypes.
show_layer_names: whether to display layer names.
rankdir: `rankdir` argument passed to PyDot,
a string specifying the format of the plot:
'TB' creates a vertical plot;
'LR' creates a horizontal plot.
expand_nested: Whether to expand nested models into clusters.
dpi: Dots per inch.
import tensorflow as tf
from keras.utils.vis_utils import plot_model
num_file = "01"
file_name_f = "model_" + num_file + "_f.png"
tf.keras.utils.plot_model(model, to_file=file_name_f, show_shapes=True, show_dtype=False, show_layer_names=False, rankdir='TB', expand_nested=False, dpi=96)
#print("f\n\n", f, "\n")
#print(DECODER, "\n")
for i, layer in enumerate(model.layers):
#if 'conv' in layer.name:
if layer.weights:
print(" ", layer.name, end=" ")
print(layer.weights[0].shape)
#print(layer.weights[1].shape)
else:
print(" ",layer.name)
print(i,'-' * 30)
After some changing of code, now should be able to run with tensorflow 2.6.4, for other using package information, you can see in My environments.txt , my project can using the following package and success to run the plot_mode.
GitHub:https://github.com/Qinbf/plot_model.git
plot_model is a API for model visualization reference to tensorflow.keras.utils.plot_model.
Before installing plot_model, please install one of its engines: TensorFlow, Keras.
You may also consider installing the following :
pip install pydotplus
pip install graphviz
- !!!!! Finally,download and install graphviz to plot model graphs. !!!!!
Then, you can install plot_model itself. There are two ways to install plot_model:
- Install plot_model from PyPI (recommended):
Note: These installation steps assume that you are on a Linux or Mac environment.
If you are on Windows, you will need to remove sudo
to run the commands below.
sudo pip install plot_model
If you are using a virtualenv, you may want to avoid using sudo:
pip install plot_model
- Alternatively: install plot_model from the GitHub source:
First, clone plot_model using git
:
git clone https://github.com/Qinbf/plot_model.git
Then, cd
to the plot_model folder and run the install command:
cd plot_model
sudo python setup.py install
API is similar to tensorflow.keras.utils.plot_model
from plot_model import plot_model
plot_model(model)
default parameters:
plot_model(model, to_file='./model.png', show_shapes=True, show_layer_names=False, rankdir='TB', expand_nested=False, style=0, color=True, dpi=96)
color: whether to display color. Default True.
style: 0 new style. 1 original style. Default 0.