This README explains how to use the trained classifier (ResNet) and segmentation model (U-Net) in your project.
scratch_detector/
├── data/
│ ├── raw/
│ │ ├── good/
│ │ ├──bad/
│ │ ├── masks/
│ ├── splits/
│
├── src/
│ ├── preprocess_dataset.py
│ ├── train_classifier.py
│ ├── train_segmentation.py
│ ├── inference.py
│
├── models/
│ ├── trained_weights
│
├── results/
│ ├── metrics/
│ └── plots/
│
├── outputs/
│ ├── test_results/
│
├── README.md
├── requirements.txt
git clone <your_repo_link>
cd scratch_detectorpip install -r requirements.txtMake sure you have Python 3.10+.
Place your images in:
data/raw/good/
data/raw/bad/
data/raw/masks/ # segmentation masks for bad images
Then generate train/val/test splits:
python src/preprocess_dataset.pyThis creates:
data/splits/train.csv
data/splits/val.csv
data/splits/test.csv
To train the ResNet-based scratch vs no-scratch classifier:
python src/train_classifier.pyAfter training, the model will be saved in:
models/trained_weights/resnet.pth
To train the segmentation model:
python src/train_segmentation.pyAfter training, the model will be saved in:
models/trained_weights/unet.pth
- All Performance metrics and plots will appear inside the models or results folders.
- Check them after training.
Use inference.py for classification and segmentation.
python src/inference.py --img path/to/image.jpg --task classify --model models/resnet_classifier.pthpython src/inference.py --img path/to/image.jpg --task segment --model models/unet_segmenter.pthpython src/inference.py --folder path/to/images --task classifyThe predictions will be saved in the ouput folder.
- Ensure masks are binary
- Maintain consistent image sizes
- Use CUDA for faster training
- Keep folder names exactly
good/,bad/,masks/