Skip to main content

A CNN visualization library for pytorch

Project description

Title icon

forks forks pip downloads MIT License python_version

Introduction

CNNs do a great job at recognizing images (when appropriately trained).

Problems arrive when it comes to interpret the network: although one coded the network in question, and one knows all the tips and tricks necessary to train it efficiently, one might ignore how it generates the output from a given image.

Torchlurk aims at helping the user in that sense: it provides an interface to visualize a Pytorch network in an efficient yet simple manner, similarly to Microscope.

All you need is the trained pytorch network and its training set. That's it.

Installation ☕

Torchlurk is available on pip! Just run:
pip install torchlurk

Overview ☝

demo gif

Documentation 📚

Torchlurk has an online documentation which gets regularly updated.

Quick Start ⌛

Your training set should follow the following structure in order for the lurker to load properly your datas:

.
├── src                  
│   ├── name_class1
│   │   ├── class1id_1.jpg
│   │   ├── class1id_2.jpg
│   │   ├── ...
│   ├── name_class2
│   │   ├── class2id_1.jpg
│   │   ├── class2id_2.jpg
│   │   ├── ...
│    ├── ...

1. Instanciation

import torchlurk
import torch

# load the trained model
your_model = ModelClass() 
your_model.load_state_dict(torch.load(PATH))

# the preprocess used for the training
preprocess = transforms.Compose(...)

# and instanciate a lurker
lurker = Lurk(your_model,
          preprocess,
          save_gen_imgs_dir='save/dir',
          save_json_path='save/dir',
          imgs_src_dir=".source/dir",
          side_size=224)

2. Layer Visualization

The layer visualization is an artificial image generated by gradient descent which aims at maximizing the acivation of a given filter: this gives useful insights on the type of texture/colors the filter in question is looking at in inputs images.

# compute the layer visualisation for a given set of layers/filters
lurker.compute_layer_viz(layer_indx = 12,filter_indexes=[7])
# OR compute it for the whole network
lurker.compute_viz()
# plot the filters
lurker.plot_filter_viz(layer_indx=12,filt_indx=7)

3. Max Activation

The max activation represents the top N images activating a given filter the most in terms of average or max score.

#compute the top activation images
lurker.compute_top_imgs(compute_max=True,compute_avg=True)
# plot them
lurker.plot_top("avg",layer_indx=12,filt_indx=7)

3.1 Deconvolution

# plot the max activating images along with their cropped areas
lurker.plot_crop(layer_indx=2,filt_indx=15)

4. Gradients

Guided GRAD CAM is another way to check what a given filter is looking at: for more information, check this article

#compute the gradients
lurker.compute_grads()
# plot them
lurker.plot_top("avg",layer_indx=12,filt_indx=7,plot_imgs=False,plot_grads=True)

5. Histograms

Torchlurk allows you to visualize the most activating classes of the training using histograms: a very peaked distribution is often asssociated with a specialized filter.

# display the 
lurker.plot_hist(layer_indx=12,filt_indx=7,hist_type="max",num_classes=12)

6. Serving

Torchlurk is equiped with a live update tool which allows you to visualize your computed results while coding.

#serve the application on port 5001
lurker.serve(port=5001)

lurker.end_serve()

Happy Lurking!

🕵

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchlurk-0.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchlurk-0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file torchlurk-0.1.tar.gz.

File metadata

  • Download URL: torchlurk-0.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.6.9

File hashes

Hashes for torchlurk-0.1.tar.gz
Algorithm Hash digest
SHA256 d29cb94b94f01fa3b08d746664e844b836a5cf3985eb0f35078ea87a6e8a3497
MD5 f406bd1eaf20914834fc0fb604f1996f
BLAKE2b-256 89d481e8653bd00be6f5b70916b5fd9fcf2d2ceb0743e5035a341e5f6812e6b0

See more details on using hashes here.

File details

Details for the file torchlurk-0.1-py3-none-any.whl.

File metadata

  • Download URL: torchlurk-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.17

File hashes

Hashes for torchlurk-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed77565b22d9cd3cf18ded14d8f671c31638aa6ed9a22c6b02362786cad09afa
MD5 2956ed7f54394be9de2a0dfdb6cf68b1
BLAKE2b-256 7ac1280b7806828af723747107827d8332073314bc6b6a905913567b4161e764

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page