Skip to content

Latest commit

 

History

History
187 lines (133 loc) · 4.8 KB

README.md

File metadata and controls

187 lines (133 loc) · 4.8 KB

plot_model


ryuuzaki42 info - start

Tested in Google Collab

Mount the /content/drive

from google.colab import drive
drive.mount('/content/drive')

Install tensorflow 2.6.4

!pip install tensorflow==2.6.4
import tensorflow as tf
print(tf.__version__)

Install pydotplus

pip install pydotplus

Install graphviz

pip install graphviz

Clone plot_model

!git clone https://github.com/ryuuzaki42/plot_model

Load/Exec file

execfile("/content/plot_model/plot_model/plot_model.py")

Make the plot

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)

Args:

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.

Original plot

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 conv

#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)

ryuuzaki42 info - end


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.


Installation

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

Getting started

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.


Examples

ResNet

Inception

ResNeXt