Skip to content

Installation

The online documentation follows the repository's main branch. Choose the install that matches the API you want to use:

Source Install What you get
PyPI (stable) pip install torchcam Latest tagged release.
Git (main) pip install "torchcam @ git+https://github.com/frgfm/torch-cam.git" Unreleased changes matching this site.

Check the installed version when an example and your environment behave differently:

import importlib.metadata

print(importlib.metadata.version("torchcam"))

Virtual environment

Tip

You will need an environment manager, and I cannot recommend enough uv.

Create a virtual environment with your preferred Python version (3.11 or higher is required to use TorchCAM):

$ uv venv --python 3.11

$ uv pip install torchcam
$ uv pip install "torchcam @ git+https://github.com/frgfm/torch-cam.git"

System installation

You'll need Python 3.11 or higher, and a package installer like uv or pip.

$ uv pip install --system torchcam
$ uv pip install --system "torchcam @ git+https://github.com/frgfm/torch-cam.git"
$ pip install torchcam
$ pip install "torchcam @ git+https://github.com/frgfm/torch-cam.git"

Info

TorchCAM is built on top of PyTorch which is a complex dependency. Proper installation depends on your system and available hardware. You can refer to installation guide of uv which is quite detailed.

For common pitfalls (e.g. no_grad with Grad-CAM, hook cleanup, picking target_layer), see Troubleshooting.