PatchCore_anomaly_detection
PatchCore_anomaly_detection copied to clipboard
num_samples should be a positive integer value, but got num_samples=0
I ran the code and got many errors but handled to solve them somehow! here is a problem that I have. I only want to train the model on the bottle dataset and it is already in the dataset address. the original dataset has broken_large, broken_small, contaminated, and good but I do not know how to feed those 4 groups as a train/test dataset.
I also have got an error while training only on good images. I will appreciate it if you could help me
$ python train.py --phase train --dataset_path C:\\projects\\interview\\mvtec --category bottle --project_root_path C:\projects\interview\PatchCore_anomaly_detection\results --coreset_sampling_ratio 0.01 --n_neighbors 9 C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torchvision\models\detection\anchor_utils.py:63: UserWarning: Failed to initialize NumPy: module compiled against API version 0x10 but this version of numpy is 0xf (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:68.) device: torch.device = torch.device("cpu"), GPU available: False, used: False TPU available: False, using: 0 TPU cores IPU available: False, using: 0 IPUs Using cache found in C:\Users\user/.cache\torch\hub\pytorch_vision_v0.9.0 C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torchvision\models\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead. warnings.warn( C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torchvision\models\_utils.py:223: UserWarning: Arguments other than a weight enum or
Nonefor 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing
weights=Wide_ResNet50_2_Weights.IMAGENET1K_V1. You can also use
weights=Wide_ResNet50_2_Weights.DEFAULTto get the most up-to-date weights. warnings.warn(msg) C:\projects\interview\PatchCore_anomaly_detection_2\train.py:259: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. transforms.Resize((args.load_size, args.load_size), Image.ANTIALIAS), C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\torchvision\transforms\transforms.py:332: UserWarning: Argument 'interpolation' of type int is deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum. warnings.warn( C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pytorch_lightning\trainer\optimizers.py:37: UserWarning:
LightningModule.configure_optimizersreturned
None`, this fit will run with no optimizer
rank_zero_warn(
| Name | Type | Params
0 | model | ResNet | 68.9 M 1 | criterion | MSELoss | 0 2 | inv_normalize | Normalize | 0
0 Trainable params
68.9 M Non-trainable params
68.9 M Total params
275.533 Total estimated model params size (MB)
Traceback (most recent call last):
File "C:\projects\interview\PatchCore_anomaly_detection_2\train.py", line 437, in
The dataset loader in the train script has the file extension hard coded to ".png". If you change it to the file extension that you have it will work.
for defect_type in defect_types:
if defect_type == 'good':
img_paths = glob.glob(os.path.join(self.img_path, defect_type) + "/*.png")
img_tot_paths.extend(img_paths)
gt_tot_paths.extend([0]*len(img_paths))
tot_labels.extend([0]*len(img_paths))
tot_types.extend(['good']*len(img_paths))
else:
img_paths = glob.glob(os.path.join(self.img_path, defect_type) + "/*.png")
gt_paths = glob.glob(os.path.join(self.gt_path, defect_type) + "/*.png)
img_paths.sort()
gt_paths.sort()
img_tot_paths.extend(img_paths)
gt_tot_paths.extend(gt_paths)
tot_labels.extend([1]*len(img_paths))
tot_types.extend([defect_type]*len(img_paths))