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

Add support for batch processing #139

Closed
Tracked by #136
frgfm opened this issue Feb 6, 2022 · 0 comments · Fixed by #143
Closed
Tracked by #136

Add support for batch processing #139

frgfm opened this issue Feb 6, 2022 · 0 comments · Fixed by #143
Assignees
Labels
module: methods Related to torchcam.methods type: improvement New feature or request
Milestone

Comments

@frgfm
Copy link
Owner

frgfm commented Feb 6, 2022

Following up on #79 & #90, the CAM methods should be able to process batches. With the way they are computed, here is the proposal to handle two cases:

  • if the model got an input_tensor with batch size = 1, then the CAM extractor can only be passed either a single integer (class index) or a list of class indices of length 1.
  • if the model gets a tensor with batch_size = N, then:
    • if the CAM extractor receives class_idx: int, it will return a tensor of shape (N, H, W) which is the class activation map for class corresponding to index = class_idx, for each element of the input batch
    • if the CAM extractor receives class_idx: List[int] (of size N), it will return a tensor of shape (N, H, W) where element k, along the batch axis, will be the class activation map for class corresponding to index = class_idx[k] for the k-th element of the input batch.

So far, for more complex behaviours, I cannot foresee a way to do it efficiently (without breaking the backprop).

@frgfm frgfm added type: improvement New feature or request module: methods Related to torchcam.methods labels Feb 6, 2022
@frgfm frgfm added this to the 0.4.0 milestone Feb 6, 2022
@frgfm frgfm self-assigned this Feb 6, 2022
@frgfm frgfm linked a pull request Feb 6, 2022 that will close this issue
@frgfm frgfm closed this as completed in #143 Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: methods Related to torchcam.methods type: improvement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant