This minor release makes sure the example scripts are compatible with the last release API changes.
Note: TorchCAM 0.4.1 requires PyTorch 2.0.0 or higher.
Highlights
Minor new API for activation & gradient hook control
Before
import torch
from torchvision.models import resnet18
from torchcam.methods import LayerCAM
model = resnet18(pretrained=True).eval()
# Hooks are enabled by default
cam_extractor = LayerCAM(model)
# Disable it to do inference without recording CAMs (save some RAM & latency)
cam_extractor._hooks_enabled = False
img = read_image("path/to/your/image.png")
input_tensor = normalize(resize(img, (224, 224)) / 255., [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
with torch.inference_mode():
out = model(input_tensor.unsqueeze(0))
# Re-enable it
cam_extractor._hooks_enabled = TrueAfter
import torch
from torchvision.models import resnet18
from torchcam.methods import LayerCAM
model = resnet18(pretrained=True).eval()
# Hooks are enabled by default
cam_extractor = LayerCAM(model)
# Disable it to do inference without recording CAMs (save some RAM & latency)
- cam_extractor._hooks_enabled = False
+ cam_extractor.disable_hooks()
img = read_image("path/to/your/image.png")
input_tensor = normalize(resize(img, (224, 224)) / 255., [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
with torch.inference_mode():
out = model(input_tensor.unsqueeze(0))
# Re-enable it
- cam_extractor._hooks_enabled = True
+ cam_extractor.enable_hooks()What's Changed
Miscellaneous
- chore(deps): bump ruff to 0.2.0 by @frgfm in #235
- build(deps-dev): bump ruff from 0.3.0 to 0.4.1 by @dependabot[bot] in #241
- build(deps-dev): bump mypy from 1.8.0 to 1.10.0 by @dependabot[bot] in #243
- build(deps): bump ruff from 0.4.1 to 0.4.9 by @dependabot[bot] in #254
- build(deps): bump ruff from 0.4.9 to 0.4.10 by @dependabot[bot] in #255
- build(deps-dev): bump ruff from 0.4.10 to 0.5.0 by @dependabot[bot] in #258
- build(deps): bump ruff from 0.5.0 to 0.5.1 by @dependabot[bot] in #259
- build(deps): bump ruff from 0.5.1 to 0.5.2 by @dependabot[bot] in #260
- build(deps-dev): bump ruff from 0.5.2 to 0.5.5 by @dependabot[bot] in #266
- build(deps): bump ruff from 0.5.5 to 0.5.7 by @dependabot[bot] in #269
- build(deps): bump ruff from 0.5.7 to 0.6.1 by @dependabot[bot] in #272
- build(deps): bump actions/download-artifact from 2 to 4.1.7 in /.github/workflows by @dependabot[bot] in #275
- build(deps): bump ruff from 0.6.1 to 0.8.2 by @dependabot[bot] in #291
- build(deps): bump the gh-actions group across 1 directory with 5 updates by @dependabot[bot] in #293
- build(deps): bump ruff from 0.8.2 to 0.8.4 by @dependabot[bot] in #295
- ci(dependabot): change the update rule for Github actions by @frgfm in #296
- build(deps): bump astral-sh/setup-uv from 4 to 5 by @dependabot[bot] in #297
- ci(github): bump uv to 0.5.13 by @frgfm in #298
- build(deps): update pre-commit requirement from <4.0.0,>=3.0.0 to >=3.0.0,<5.0.0 by @dependabot[bot] in #283
- docs(readme): update installation instructions and badges by @frgfm in #299
- build(deps-dev): bump mypy to 1.14.0 by @frgfm in #300
- build(deps): bump ruff from 0.8.4 to 0.9.7 by @dependabot[bot] in #310
- build(deps): bump JamesIves/github-pages-deploy-action from 4.7.2 to 4.7.3 by @dependabot[bot] in #311
- docs: update copyright year by @frgfm in #314
- build(deps-dev): bump mypy to 1.15.0 by @frgfm in #315
- build(deps): bump ruff from 0.9.7 to 0.9.9 by @dependabot[bot] in #313
- build(deps): bump astral-sh/setup-uv from 5 to 6 by @dependabot[bot] in #327
- build(deps): bump webfactory/ssh-agent from 0.9.0 to 0.9.1 by @dependabot[bot] in #321
- build(deps): bump ruff from 0.9.9 to 0.11.9 by @dependabot[bot] in #329
- build(deps): bump actions/setup-python from 5 to 6 by @dependabot[bot] in #351
- build(deps): bump actions/github-script from 7 to 8 by @dependabot[bot] in #350
- build(deps): bump amannn/action-semantic-pull-request from 5 to 6 by @dependabot[bot] in #347
- build(deps): bump actions/download-artifact from 4 to 5 by @dependabot[bot] in #343
- build(deps): bump actions/checkout from 4 to 5 by @dependabot[bot] in #346
- docs(readme): fix badge by @frgfm in #362
- build(deps): bump actions/labeler from 5 to 6 by @dependabot[bot] in #359
- build(deps): bump astral-sh/setup-uv from 6 to 7 by @dependabot[bot] in #360
- build(deps): bump actions/download-artifact from 5 to 6 by @dependabot[bot] in #366
- build(deps): bump actions/upload-artifact from 4 to 5 by @dependabot[bot] in #365
- build(deps): bump ruff from 0.14.1 to 0.14.2 by @dependabot[bot] in #364
New Contributors
- @dependabot[bot] made their first contribution in #241
Full Changelog: v0.4.0...v0.4.1