amazon-science / patchcore-inspection

Apache License 2.0
733 stars 149 forks source link

How to train my own data ? #82

Open Jialiang123 opened 1 year ago

Jialiang123 commented 1 year ago

Thanks,How to train my own data and implement reasoning on a single graph or multiple graphs?

romanvelichkin commented 1 year ago

Code was made to be used only with provided examples. To train on your own data code will require some modifications.

This is a fast solution, not for production usage

  1. create folder for you data in "mvtec_anomaly_detection" folder - you folder must be with "bottle", "cable" etc.
  2. inside your folder orginize data similar to mvtec_anomaly with "good" and other folders.
  3. modify "run_pathcore.py": in run > if save_segmentation_images before patchcore.utils.plot_segmentation_images add code:
    image_save_path = os.path.join(
                    run_save_path, "segmentation_images", dataset_name
                )
                os.makedirs(image_save_path, exist_ok=True)

    This will allow you to save segmented images.

  4. run patchcore training with bash/cmd command: python bin/run_patchcore.py --gpu 0 --seed 0 --save_segmentation_images "results_path" 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 224 --imagesize 224 -d "your_train_dataset" mvtec "mvtec_anomaly_detection"

"results_path" - path to place where you will save training results "mvtec_anomaly_detection" - path to place where you keep mvtec datasets (you dataset must be with them) "your_train_dataset" - name of your dataset (name of your folder in mvtec folder)

  1. If something will go wrong then check errors, carefully read README.md of this repo, check code - some things are missed in READMe.md (like how to properly save segmentation images).

However it's a fast solution, for testing purpose. Patchcore requires a lot of work before it could be used on production.

wyweather commented 8 months ago

Why didn't I find the mvtec folder? Where should I put my own dataset folder and where to change parameters