-
Notifications
You must be signed in to change notification settings - Fork 677
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]: ValueError: The .compute()
return of the metric logged as 'pixel_BinaryROC' must be a tensor.
#1460
Comments
when I add task to the metric_cls in the following function, this bug generates, (using torchmetrics v1.2) def metric_collection_from_names(metric_names: list[str], prefix: str | None) -> AnomalibMetricCollection:
|
Hi @jamal-saeedi, if you use a recent torchmetrics such 1.2, you could get some issues. Please refer to this issue and the PR. Once this PR is merged on the torchmetrics side, we will bump the version |
hi, the issue is related to the class rapper being used in new version of torch metric without using init, and it can be resolved by directly using the class like BinaryF1Score or BinaryROC, but I would like to know about the possibility of using the rapper as base class. |
Describe the bug
File "/mnt/d/projects/pytorch/torch_dataset/mvtec_test.py", line 69, in
trainer.fit(model=model, datamodule=datamodule)
ValueError: The
.compute()
return of the metric logged as 'pixel_BinaryROC' must be a tensor. Found (tensor([0.0000, 0.1008, 0.1138, ..., 1.0000, 1.0000, 1.0000], device='cuda:0'), tensor([0.0000, 0.9915, 0.9953, ..., 1.0000, 1.0000, 1.0000], device='cuda:0'), tensor([1.0000, 1.0000, 1.0000, ..., 0.6186, 0.6186, 0.6185], device='cuda:0'))Dataset
MVTec
Model
PADiM
Steps to reproduce the behavior
from future import annotations
import os
from pathlib import Path
from typing import Any
from git.repo import Repo
current_directory = Path.cwd()
root_directory = current_directory
os.chdir(current_directory)
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
from pytorch_lightning import Trainer
from torchvision.transforms import ToPILImage
from anomalib.config import get_configurable_parameters
from anomalib.data import get_datamodule
from anomalib.data.utils import read_image
from anomalib.deploy import OpenVINOInferencer
from anomalib.models import get_model
from anomalib.pre_processing.transforms import Denormalize
from anomalib.utils.callbacks import LoadModelCallback, get_callbacks
MODEL = "padim" # 'padim', 'cflow', 'stfpm', 'ganomaly', 'dfkde', 'patchcore'
CONFIG_PATH = root_directory / f"anomalib/models/{MODEL}/config.yaml"
with open(file=CONFIG_PATH, mode="r", encoding="utf-8") as file:
print(file.read())
config = get_configurable_parameters(config_path=CONFIG_PATH)
datamodule = get_datamodule(config)
datamodule.prepare_data() # Downloads the dataset if it's not in the specified
root
directorydatamodule.setup() # Create train/val/test/prediction sets.
i, data = next(enumerate(datamodule.val_dataloader()))
print(data.keys())
print(data["image"].shape, data["mask"].shape)
from anomalib.pre_processing.transforms import Denormalize
def show_image_and_mask(sample: dict[str, Any], index: int) -> Image:
img = ToPILImage()(Denormalize()(sample["image"][index].clone()))
msk = ToPILImage()(sample["mask"][index]).convert("RGB")
Visualize an image with a mask
show_image_and_mask(data, index=0)
Set the export-mode to OpenVINO to create the OpenVINO IR model.
config.optimization.export_mode = "openvino"
config.optimization.export_mode = "torch"
Get the model and callbacks
model = get_model(config)
callbacks = get_callbacks(config)
trainer = Trainer(**config.trainer, callbacks=callbacks) #
trainer.fit(model=model, datamodule=datamodule)
OS information
OS information:
Expected behavior
.
Screenshots
No response
Pip/GitHub
pip
What version/branch did you use?
No response
Configuration YAML
Logs
Code of Conduct
The text was updated successfully, but these errors were encountered: