openvinotoolkit / anomalib

An anomaly detection library comprising state-of-the-art algorithms and features such as experiment management, hyper-parameter optimization, and edge inference.
https://anomalib.readthedocs.io/en/latest/
Apache License 2.0
3.8k stars 674 forks source link

[Bug]: Using absolute path as root in datamodule creates too many folders when testing #1819

Open LeAyky opened 8 months ago

LeAyky commented 8 months ago

Describe the bug

Hello there,

Trying out the new API (great job everybody!), I noticed that, when creating the datamodule with custom data, using an absolute path as the root leads to the testing results being saved in new folders in the results directory.

Dataset

Folder

Model

PatchCore

Steps to reproduce the behavior

# Import the datamodule
from anomalib.data import Folder

# Create the datamodule
datamodule = Folder(
    name="Custom_Dataset_test",
    root="/home/deeplearning/Pictures/anomalib/custom_dataset",
    normal_dir="train/good",
    abnormal_dir="test/bad",
    normal_test_dir="test/good",
    task="classification",
    image_size=(256, 256),
)

# Setup the datamodule
datamodule.setup()

# Import the required modules
from anomalib.data import MVTec
from anomalib.models import Patchcore
from anomalib.engine import Engine

# Initialize the datamodule, model and engine
model = Patchcore()
engine = Engine()

# Train the model
engine.fit(datamodule=datamodule, model=model)

engine.test(datamodule=datamodule, model=model)

OS information

OS information:

Expected behavior

I expected it to save it to: path/to/my/results/patchcore/name/run/images/good and path/to/my/results/patchcore/name/run/images/bad

The above would be the behavior for previous anomalib versions using CLI.

However, this is what I got now: path/to/my/results/Patchcore/Custom_Dataset_test/latest/images/deeplearning/Pictures/anomalib/custom_dataset/test/bad and path/to/my/results/Patchcore/Custom_Dataset_test/latest/images/deeplearning/Pictures/anomalib/custom_dataset/test/good.

So the whole root path gets appended, leading to the testing results path being: path/to/my/results/Patchcore/name/latest/images/ROOT_PATH/ABNORMAL_DIR and path/to/my/results/Patchcore/name/latest/images/ROOT_PATH/NORMAL_TEST_DIR

while it should be path/to/my/results/Patchcore/name/latest/images/ABNORMAL_DIR and path/to/my/results/Patchcore/name/latest/images/NORMAL_TEST_DIR

I hope I have illustrated the problem sufficiently. One solution, of course, would be to save the dataset closer to my notebook, where I use the testing functionality but I would like to refrain from that.

Maybe a save_dir parameter help here, or maybe I am overlooking something.

Anyhow, I hope you can take a look into it. I thank you in advance for your help and let me know if you need further information.

Screenshots

No response

Pip/GitHub

GitHub

What version/branch did you use?

No response

Configuration YAML

-

Logs

-

Code of Conduct

francescodalmonte commented 6 months ago

I am having the same issue... is there any workaround for this?