Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hooks once we're done with CAM extractors #197

Closed
Tracked by #136
frgfm opened this issue Dec 21, 2022 · 0 comments · Fixed by #198
Closed
Tracked by #136

Remove hooks once we're done with CAM extractors #197

frgfm opened this issue Dec 21, 2022 · 0 comments · Fixed by #198
Assignees
Labels
type: improvement New feature or request
Milestone

Comments

@frgfm
Copy link
Owner

frgfm commented Dec 21, 2022

When an extractor is dereferenced, its hooks are not removed by default

extractor = LayerCAM(model)
del extractor
# Hooks are still on the model

A call to .remove_hooks is required to fix that.

What would avoid problems is to remove them when it's deleted:

extractor = LayerCAM(model)
del extractor
# No more hooks of that extractor on the model

but also when it's dereferenced

extractor = LayerCAM(model)
extractor = LayerCAM(model)
# No more hooks of the initial extractor on the model

An option would be to use a context manager

with LayerCAM(model) as extractor:
    # do stuff
# No more hooks on the model
@frgfm frgfm added the type: improvement New feature or request label Dec 21, 2022
@frgfm frgfm added this to the 0.4.0 milestone Dec 21, 2022
@frgfm frgfm self-assigned this Dec 21, 2022
@frgfm frgfm changed the title Remove hooks when deleting CAM extractors Remove hooks once we're done with CAM extractors Dec 21, 2022
@frgfm frgfm mentioned this issue Dec 21, 2022
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant