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

[Bug]: Unable to initialize model #1877

Closed
1 task done
OneBugMaker opened this issue Mar 20, 2024 · 6 comments
Closed
1 task done

[Bug]: Unable to initialize model #1877

OneBugMaker opened this issue Mar 20, 2024 · 6 comments

Comments

@OneBugMaker
Copy link

Describe the bug

problem

When I tried to initialize the model in anomalib, an error occurred. This happened during the initialization phase without any further operations. Both "Padim" and "Patchcore" encountered the same issue. The detailed error message is as follows:


RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_21240\545706316.py in <cell line: 1>()
----> 1 model = Padim()

D:\ML\0-PHD2\27_IDD\MyIDD\new_19_14_42\anomalib\src\anomalib\models\image\padim\lightning_model.py in init(self, backbone, layers, pre_trained, n_features)
48 super().init()
49
---> 50 self.model: PadimModel = PadimModel(
51 backbone=backbone,
52 pre_trained=pre_trained,

D:\ML\0-PHD2\27_IDD\MyIDD\new_19_14_42\anomalib\src\anomalib\models\image\padim\torch_model.py in init(self, layers, backbone, pre_trained, n_features)
99 self.idx: torch.Tensor
100 self.loss = None
--> 101 self.anomaly_map_generator = AnomalyMapGenerator()
102
103 self.gaussian = MultiVariateGaussian()

D:\ML\0-PHD2\27_IDD\MyIDD\new_19_14_42\anomalib\src\anomalib\models\image\padim\anomaly_map.py in init(self, sigma)
24 super().init()
25 kernel_size = 2 * int(4.0 * sigma + 0.5) + 1
---> 26 self.blur = GaussianBlur2d(kernel_size=(kernel_size, kernel_size), sigma=(sigma, sigma), channels=1)
27
28 @staticmethod

D:\ML\0-PHD2\27_IDD\MyIDD\new_19_14_42\anomalib\src\anomalib\models\components\filters\blur.py in init(self, sigma, channels, kernel_size, normalize, border_type, padding)
66 self.kernel = normalize_kernel2d(self.kernel)
67 self.kernel.unsqueeze_(0).unsqueeze_(0)
---> 68 print(self.kernel.shape, self.channels)
69 self.kernel = self.kernel.expand(self.channels, -1, -1, -1)
70 self.kernel = self.kernel.expand(self.channels, -1, -1, -1)

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)

environment

python==3.10.0
torch==2.1.0+cu121
anomalib==1.1.0dev

Dataset

MVTec

Model

PatchCore

Steps to reproduce the behavior

When I tried to initialize the model in anomalib, an error occurred.

This happened during the initialization phase without any further operations.

Both "Padim" and "Patchcore" encountered the same issue.

OS information

OS information:

  • OS: [Windows 11]
  • Python version: [ 3.10.0]
  • Anomalib version: [1.1.0dev]
  • PyTorch version: [2.1.0]
  • CUDA/cuDNN version: [12.1]
  • GPU models and configuration: [GeForce RTX 2060]

Expected behavior

Resolve this bug and successfully use Padim and Patchcore models

Screenshots

image

Pip/GitHub

GitHub

What version/branch did you use?

No response

Configuration YAML

i do not know

Logs

i do not know

Code of Conduct

  • I agree to follow this project's Code of Conduct
@samet-akcay
Copy link
Contributor

Can you show the full code you ran? It is a bit hard to find out the problem from model = Padim()

@OneBugMaker
Copy link
Author

Thank you for your comment.
I imported the required modules in Jupyter Notebook and attempted to initialize the model, but encountered an error, as shown in the screenshot.

image

@samet-akcay
Copy link
Contributor

samet-akcay commented Mar 20, 2024

I have tried it on both MacOS and Linux, which worked fine. Can you check if your installation is correct?

On MacOS
image

On Linux
image

@OneBugMaker
Copy link
Author

Thank you for your efforts!
The good news is that this issue has been resolved. Here are the specific steps taken to address it:

Open the file: anomalib/src/anomalib/models/components/filters/blur.py
Locate line 67: self.kernel.unsqueeze_(0).unsqueeze_(0)
Replace it with: self.kernel.unsqueeze_(0)

@luizfelippesr
Copy link

#1944

@ghost
Copy link

ghost commented Apr 27, 2024

Thanks OneBugMaker. Faced same issue. Resolved.
In our case the file is located in:
C:\Users\ADMIN\anaconda3\envs\anomalib_env\Lib\site-packages\anomalib\models\components\filters\blur.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants