tiskw / patchcore-ad

Unofficial implementation of PatchCore and several additional experiments.
MIT License
12 stars 1 forks source link

Embedding dimension 0 #4

Closed DHAiRYA2048 closed 7 months ago

DHAiRYA2048 commented 8 months ago

I am getting this error (shown in image) when I run main.py using python main.py train -i data_train -o ./index.faiss. some info about the dataset;

image

DHAiRYA2048 commented 8 months ago

Here is the error which shows why embedding dimension is (0,). image

Here is the part of code where the error is occurring. embeddings_list remains empty. Any idea why is this happening? image

tiskw commented 7 months ago

Hi @DHAiRYA2048,

Thank you for your issue post with detailed information and sorry for my late response.

Honestly, I'm a bit confused because the 1st and 2nd images you've posted do not match (the feature extraction step finished but the feature shape is strange in the 1st image, however in the 2nd image, the script stopped by the error during the feature extraction step...).

However, one possibility is that the training images you've placed under data_train/ are not recognized. For example, you can replicate the error of your 2nd image by the following:

# Create an empty directory
mkdir data_dummy

# Train without training images.
python3 main.py train -i data_dummy -o ./index.faiss

This is just my guess, but the suffix of your training image is neither ".jpg" nor ".png", isn't it? I'm sorry it is not written in the README, but the image files used for the training should have the suffix ".jpg" or ".png". This behavior comes from the following code:

patchcore-ad/patchcore/dataset.py L.205

self.paths = [path for path in self.root.glob("**/*") if path.suffix in [".jpg", ".png"]]

If you want to use the other types of image files as training data, you have 2 choices:

Before: patchcore-ad/patchcore/dataset.py L.205

self.paths = [path for path in self.root.glob("**/*") if path.suffix in [".jpg", ".png"]]

After: patchcore-ad/patchcore/dataset.py L.205

self.paths = [path for path in self.root.glob("**/*") if path.suffix in [".jpg", ".png", ".webp"]]

If my guess is not correct and your problem is not resolved, please let me know again with the more detailed information of your training data.

Regards, Tetsuya

DHAiRYA2048 commented 7 months ago

Thank you for your response. My files were in .bmp format, I didn't check the dataset.py file before running, my bad. Now it runs fine. If I face some other error, I will let you know in another issue.