amazon-science / patchcore-inspection

Apache License 2.0
719 stars 146 forks source link

Visualising segmented images #23

Open svmaskery opened 2 years ago

svmaskery commented 2 years ago

When I add the --save_segmentation_images tag as shown below to train the model, I get an error as shown below. The same thing happens when I try to run the evaluation too.

python bin/run_patchcore.py --gpu 0 --seed 0 --save_patchcore_model --save_segmentation_images \
--log_group IM224_WR50_L2-3_P01_D1024-1024_PS-3_AN-1_S0 --log_online --log_project MVTecAD_Results results \
patch_core -b wideresnet50 -le layer2 -le layer3 --faiss_on_gpu \
--pretrain_embed_dimension 1024  --target_embed_dimension 1024 --anomaly_scorer_num_nn 1 --patchsize 3 \
sampler -p 0.1 approx_greedy_coreset dataset --resize 256 --imagesize 224 "${dataset_flags[@]}" mvtec $datapath

Error traceback:

Traceback (most recent call last):                                                                                                                                                                         
  File "bin/run_patchcore.py", line 435, in <module>
    main()
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/click/core.py", line 1689, in invoke
    return _process_result(rv)
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/click/core.py", line 1626, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "bin/run_patchcore.py", line 166, in run
    patchcore.utils.plot_segmentation_images(
  File "/home/shreevijay/anaconda3/envs/patch_off/lib/python3.8/site-packages/patchcore/utils.py", line 51, in plot_segmentation_images
    image = image_transform(image)
  File "bin/run_patchcore.py", line 149, in image_transform
    dataloaders["testing"].dataset.transform_std
AttributeError: 'MVTecDataset' object has no attribute 'transform_std'

'transform_std', 'transform_mean' and similar attributes are undefined and shows an AttributeError. Please check the code associated to the tag --save_segmentation_images.

Confusezius commented 2 years ago

Oh thanks for noticing - when moving to the official repository, it seems that two dataset attributes got lost!

To address this, it should hopefully be enough to assign the attributes:

self.transform_mean = IMAGENET_MEAN
self.transform_std = IMAGENET_STD

in src/patchcore/datasets/mvtec > MVTecDataset > __init__().

Let me know if that worked or if other errors are thrown!

We will hopefully be able to push a fix soon :).

svmaskery commented 2 years ago

That did not exactly fix the issue but I got it running, no problem. The --save_segmentation_images is working fine as now but please do the necessary changes. Anyways, the mean and standard deviation is taken from the imagenet dataset, how will the results compare if a custom dataset is used. Does it make a difference?

PauloFavero commented 1 year ago

Give a look at https://github.com/amazon-science/patchcore-inspection/issues/80#issuecomment-1673587279

wyweather commented 7 months ago

Give a look at #80 (comment)

Hello, how should I do to get a prediction on the image, like this? ![Uploading 微信图片_20240131225259.png…]()