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

fix bug expand(torch.FloatTensor{[1, 1, 1, 33, 33]}, size=[1, -1, -1,… #1892

Closed
wants to merge 5 commits into from

Conversation

qkhanh711
Copy link

@qkhanh711 qkhanh711 commented Mar 22, 2024

… -1]): the number of sizes provided (4) must be greater or equal to the number of dimensions in the tensor (5)

📝 Description

✨ Changes

Select what type of change your PR is:

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔨 Refactor (non-breaking change which refactors the code base)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

… -1]): the number of sizes provided (4) must be greater or equal to the number of dimensions in the tensor (5)
@qkhanh711 qkhanh711 requested a review from samet-akcay as a code owner March 22, 2024 05:54
@github-actions github-actions bot added the Docs label Mar 22, 2024
@samet-akcay
Copy link
Contributor

Hi @qkhanh711, can you provide a more descriptive title and description to the PR?

@qkhanh711
Copy link
Author

Hi @qkhanh711, can you provide a more descriptive title and description to the PR?

It happened when I clone anomalib repository. After installing, I have ran the 201_fastflow.ipynb (anomalib/notebooks/200_models/)
and change the model from Fastflow to Patchcore
And I got this error:

`---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[7], line 1
----> 1 model = Patchcore(
2 coreset_sampling_ratio=0.001
3 )

File ~/Code/computer_vision/EvaluateAD/anomalib/src/anomalib/models/image/patchcore/lightning_model.py:51, in Patchcore.init(self, backbone, layers, pre_trained, coreset_sampling_ratio, num_neighbors)
41 def init(
42 self,
43 backbone: str = "wide_resnet50_2",
(...)
47 num_neighbors: int = 9,
48 ) -> None:
49 super().init()
---> 51 self.model: PatchcoreModel = PatchcoreModel(
52 backbone=backbone,
53 pre_trained=pre_trained,
54 layers=layers,
55 num_neighbors=num_neighbors,
56 )
57 self.coreset_sampling_ratio = coreset_sampling_ratio
58 self.embeddings: list[torch.Tensor] = []

File ~/Code/computer_vision/EvaluateAD/anomalib/src/anomalib/models/image/patchcore/torch_model.py:54, in PatchcoreModel.init(self, layers, backbone, pre_trained, num_neighbors)
...
---> 68 self.kernel = self.kernel.expand(self.channels, -1, -1, -1)
69 self.border_type = border_type
70 self.padding = padding

RuntimeError: expand(torch.FloatTensor{[1, 1, 1, 33, 33]}, size=[1, -1, -1, -1]): the number of sizes provided (4) must be greater or equal to the number of dimensions in the tensor (5)
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...`

@ashwinvaidya17
Copy link
Collaborator

@qkhanh711 are you using the latest main branch? I am not able to reproduce the issue locally.
These are my relevant changes to 201_fastflow.ipynb

datamodule = MVTec(
    root=dataset_root,
    category="bottle",
    image_size=[256, 256],
    train_batch_size=32,
    eval_batch_size=32,
    num_workers=0,
    task=task,
)

model = Patchcore(backbone="wide_resnet50_2")

engine = Engine(
    pixel_metrics="AUROC",
    accelerator="auto",  # \<"cpu", "gpu", "tpu", "ipu", "hpu", "auto">,
    devices=1,
    logger=False,
)

@qkhanh711
Copy link
Author

@qkhanh711 are you using the latest main branch? I am not able to reproduce the issue locally. These are my relevant changes to 201_fastflow.ipynb

datamodule = MVTec(
    root=dataset_root,
    category="bottle",
    image_size=[256, 256],
    train_batch_size=32,
    eval_batch_size=32,
    num_workers=0,
    task=task,
)

model = Patchcore(backbone="wide_resnet50_2")

engine = Engine(
    pixel_metrics="AUROC",
    accelerator="auto",  # \<"cpu", "gpu", "tpu", "ipu", "hpu", "auto">,
    devices=1,
    logger=False,
)

yes, I'm using the main branch of https://github.com/openvinotoolkit/anomalib.git and a met this.
anw, thank you for your answer.
Screenshot from 2024-03-25 22-35-29
ut with the original repository, I still encountered this bug

@windhorse777
Copy link

do you solve this problem? I enchanted the same bug when running the 000 geting__started

@qkhanh711
Copy link
Author

do you solve this problem? I enchanted the same bug when running the 000 geting__started
in line 68 of anomalib/src/anomalib/models/components/filters/blur.py
turn self.kernel = self.kernel.expand(self.channels, -1, -1, -1) to self.kernel = self.kernel.expand(self.channels, -1, -1, -1, -1)

@samet-akcay
Copy link
Contributor

#1944 addressed this issue. This is no longer needed. Thanks a lot for reporting and proposing a fix.

@samet-akcay samet-akcay closed this Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: patchcore pytorch error
4 participants