This is a template project that demonstrates the code structure. The template can be used as follows:
- one project of the visualize-neural-networks;
- standalone;
- display any single visualization (easy for debug and collaboration);
The model we explore here is from PyTorch Hub.
-
Clone the repository to your local machine
$ git clone https://github.com/xudejing/visualize-unet2d.git
-
Install PyTorch by following the official instructions (conda prefered).
-
Install other dependency packages.
pip install -r requirements.txt
-
Download the checkpoints and put them under checkpoints. You can add more checkpoints and explore them together.
-
Download the LGG Segmentation Dataset and extract them under datasets.
-
Run the app
$ streamlit run app.py
Each visualization is organized in a specific module named with prefix vis_, for example here we have 5 visualizations which are:
- Diagram (vis_dirgram.py)
- Filter Images (vis_filter_image.py)
- Filter Stats (vis_filter_stats.py)
- Activation Map (vis_act_map.py)
- Activation Map (Channel) (vis_act_map_channel.py)
If you create new visualizations (related to 2D Unet), you also need to register them in app.py.
Inside each module, it is better to split the computation and visualization code as separate functions, such as gen_sth() and vis_sth(). This can lighten the load if you also want to use the generated image in other situations.
You can even run a single visualization by change app.py in the running command to other modules start with the prefix vis_.