A package to visualize CNN in PyTorch
Project description
pytorchvis
A library to visualize CNN in PyTorch.
Installation
pip install pytorchvis
git clone https://github.com/anujshah1003/pytorchvis
Usage
from visualize_layers import VisualizeLayers
# create an object of VisualizeLayers and initialize it with the model and
# the layers whose output you want to visualize
vis = VisualizeLayers(model,layers='conv')
# pass the input and get the output
output = model(x)
# get the intermediate layers output which was passed during initialization
interm_output = vis.get_interm_output()
# plot the featuremap of the layer which you want,
vis.plot_featuremaps(interm_output[layer_name],name='fmaps',savefig=True)
Example
Using Pretrained Alexnet
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# load the Pytorch model
model = models.alexnet(pretrained=True).to(device)
# create an object of VisualizeLayers and initialize it with the model and
# the layers whose output you want to visualize
vis = VisualizeLayers(model,layers='conv')
# load the input
x = torch.randn([1,3,224,224]).to(device)
# pass the input and get the output
output = model(x)
# get the intermediate layers output which was passed during initialization
interm_output = vis.get_interm_output()
# plot the featuremap of the layer which you want, to see what are the layers
# saved simply call vis.get_saved_layer_names
vis.get_saved_layer_names()
vis.plot_featuremaps(interm_output['features.0_conv_Conv2d'],name='fmaps',savefig=True)
the 64 featurmap from the first conv layer with a random input
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytorchvis-0.0.2.tar.gz
(3.1 kB
view hashes)
Built Distribution
pytorchvis-0.0.2-py3-none-any.whl
(16.2 kB
view hashes)
Close
Hashes for pytorchvis-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a68cee5afa93197c09461c5654dcd01dec131129173ac617a6226872b5652de |
|
MD5 | 2c093018ef2c6a1fd792515f653f4584 |
|
BLAKE2b-256 | c6f8d59e1effc9b94748453e6d1594167b8f8f41d37cad0f521c23f88cfc41be |