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]: Regular tiling in some doesn't work due to wrong shape setup. #1958

Closed
1 task done
blaz-r opened this issue Apr 7, 2024 · 0 comments · Fixed by #1959
Closed
1 task done

[Bug]: Regular tiling in some doesn't work due to wrong shape setup. #1958

blaz-r opened this issue Apr 7, 2024 · 0 comments · Fixed by #1959

Comments

@blaz-r
Copy link
Contributor

blaz-r commented Apr 7, 2024

Describe the bug

For Padim, PatchCore and Reverse Distillation, the tiling doesn't work at the moment.
This happens as the input_tensor is used to tell the shape of anomaly map:

else:
output = self.anomaly_map_generator(
embedding=embeddings,
mean=self.gaussian.mean,
inv_covariance=self.gaussian.inv_covariance,
image_size=input_tensor.shape[-2:],
)
return output

but input_tensor is overwriten in case of tiler:

if self.tiler:
input_tensor = self.tiler.tile(input_tensor)

which leads to shape mismatch.

Dataset

MVTec

Model

Other (please specify in the field below)

Steps to reproduce the behavior

from anomalib.data import MVTec
from anomalib.engine import Engine
from anomalib.models import Padim
from anomalib.callbacks import TilerConfigurationCallback

# Initialize the datamodule and model
datamodule = MVTec(num_workers=0, image_size=(128, 128))
model = Padim()

# prepare tiling configuration callback
tiler_config_callback = TilerConfigurationCallback(enable=True, tile_size=[128, 64], stride=64)

# pass the tiling configuration callback to engine
engine = Engine(image_metrics=["AUROC"], pixel_metrics=["AUROC"], callbacks=[tiler_config_callback])

# train the model (tiling is seamlessly utilized in the background)
engine.fit(datamodule=datamodule, model=model)

OS information

OS information:

  • OS: Windows 10
  • Python version: 3.10
  • Anomalib version: 1.1.0dev
  • PyTorch version: 2.1
  • GPU models and configuration: gtx 1060

Expected behavior

The procedure works even with tiler present

Screenshots

No response

Pip/GitHub

GitHub

What version/branch did you use?

No response

Configuration YAML

/

Logs

RuntimeError: Predictions and targets are expected to have the same shape, but got torch.Size([262144]) and torch.Size([524288]).

Code of Conduct

  • I agree to follow this project's Code of Conduct
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

Successfully merging a pull request may close this issue.

1 participant