-
Notifications
You must be signed in to change notification settings - Fork 709
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
Generalize PatchCore to support feature map sizes other than (28, 28). #144
Generalize PatchCore to support feature map sizes other than (28, 28). #144
Conversation
Clean up implementation of feature map size inference for PR. Fixes issue openvinotoolkit#40 for ResNets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lucas-Steinmann, thanks a ton for addressing this long-awaited issue! I only have a really minor comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution. Your solution would work, but I feel this could also be achieved without pre-computing the feature map size. Instead we could maybe infer the feature map size from the shape of the embeddings that are computed in the forward
method, here, and pass it to the anomaly map generator along with the patch scores. This would leave us with a more generic solution that would work for other backbones as well.
Yes, that would be definitely another, more generic solution. I've also mentioned it in issue #40. |
@Lucas-Steinmann thanks for clarifying. I wasn't aware of the discussion in #40. Your solution is a nice improvement already, so I would not mind merging it and extending it later. On the long term, I still think it would be better to achieve this without pre-computing the feature map size. It won't be necessary to pass a blank image or instantiate the anomaly map generator during inference. Since |
Oh sure, right. Good catch! |
@Lucas-Steinmann, following this PR to address the feature dimension issue in PatchCode, another community PR was created in #148. Based on the discussions here, the proposed solution in #148 is not limited to ResNet, but generic to other backbones as well. Does the solution in #148 suit your needs? If so we will close this PR and merge #148? We really appreciate your effort, kindly welcome you to keep contributing this repo. |
Yes, that's perfect. |
Description
This PR generalizes the PatchCore model to support different input sizes and different layers of the ResNet models.
This is implemented by inferring the pooling/downsampling ratio from the layer names.
The ratio is then used to calculate the feature map size.
The largest feature map size is used in the AnomalyMapGenerator to recreate the shape of the 2D-shape from the 1D-embedding.
It assumes the layer names and downsampling ratios are the same as in the torchvision implementation of ResNet.
Changes
Checklist