Skip to content

rtavenar/draw_convnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

draw_convnet

History

Python script for illustrating Convolutional Neural Network (ConvNet). This is based on https://github.com/gwding/draw_convnet, whose statement about using / citing the code is:

It is NOT required to cite anything to use the code.

If you are not facing space limitation and it does not break the flow of the paper, you might consider adding something like "This figure is generated by adapting the code from https://github.com/gwding/draw_convnet" (maybe in the footnote).

FYI, originally I used the code to generate the convnet figure in this paper "Automatic moth detection from trap images for pest management".

Plotting keras models

This fork allows to generate diagrams for keras sequential models, as follows:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import InputLayer, Conv2D, MaxPool2D, AvgPool2D, Flatten, Dense

model = Sequential([
    InputLayer(input_shape=(32, 32, 3)),
    Conv2D(filters=32, kernel_size=3, padding="valid"),
    MaxPool2D(pool_size=2),
    Conv2D(filters=32, kernel_size=5, padding="same"),
    AvgPool2D(pool_size=2),
    Flatten(),
    Dense(units=124),
    Dense(units=10)
])
from draw_convnet import plot_keras_convnet

plot_keras_convnet(model, font_size=6)
plt.show()  # Not required in notebooks

Alternatively, if the goal is to save the model diagram to a file, the last lines of the previous code would become:

plot_keras_convnet(model, font_size=6, to_file="convnet_keras.svg")

At the moment, the code can only deal with Sequential models with the following layers:

  • InputLayer,
  • Conv2D,
  • MaxPool2D,
  • AvgPool2D,
  • Flatten,
  • Dense

Installation

Ideally, installation should be as simple as:

python -m pip install git+https://github.com/rtavenar/draw_convnet.git

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Jupyter Notebook 70.9%
  • Python 29.1%