Skip to main content

A torch observer that wraps around wanted pytorch modules

Project description

Torch-Module-Observer

Torch-Module-Observer is a tool that uses the internal torch hook functionnalities to provide an API to observe on a model's nn.Modules.

Here is an example with a ConvObserver, but this tool can be used to observe any module, not only Convs.

image of dog

Extract features :

First layer
-------------->
Last layer

Installation

pip install torchmo

This package also works with conda and poetry.

Use

from torchmo import ConvObserver

model = ... # nn.Module

observer = ConvObserver(model) # Observe model

features = observer(tensor_imgs) # Forward pass through the observer

# After the forward pass, the observer stored the feature info

out_p = ".cache"
out_p.mkdir(exist_ok=True)

# Save figures
observer.save_figs(cache_p)

# Iterate manually through conv features
for name, output in features:
    # output is a batch of
    # output.shape (B,N,H,W)

    print(output.shape)
    break

Create your own

All you need to do is to inherit the ModuleObserver class.

See ConvObserver to see how to inherit and use.

Contribute

The project is small and some peope may have other use cases.

Poetry is being used to manage the environment.

Feel free to open an issue and/or do a PR when you believe it would help the community.

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

torchmo-1.0.6.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.

torchmo-1.0.6-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file torchmo-1.0.6.tar.gz.

File metadata

  • Download URL: torchmo-1.0.6.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.8.10 Linux/5.15.0-84-generic

File hashes

Hashes for torchmo-1.0.6.tar.gz
Algorithm Hash digest
SHA256 87cb9d1c2ab244f1237d4fc704d3072ae910c6acf89b4e10e3e8d18a17c5d139
MD5 66aff3d5c9ec09af4f3f970120ff81d9
BLAKE2b-256 7942358c2321553f8d0768b7b7a49cddbe919ed9288546ee8e784047b98a1003

See more details on using hashes here.

File details

Details for the file torchmo-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: torchmo-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.8.10 Linux/5.15.0-84-generic

File hashes

Hashes for torchmo-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 aa0a72b4b2bdc226b84d5cf2769531fb44981b6fdf00bfa7df732531c3e9145e
MD5 e7cecb33ce1fbadf9dcdf530565c5c86
BLAKE2b-256 fb98e70acb36f893ba6c7f73a56df5a7fcc40e71d803aa3e12b5cad3b5e0ec79

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