Quality inspection on a production line often means someone looking at each part. This notebook trains a small neural network to make that call from a photo: is the casting defective or fine?
Data
The Kaggle dataset of real-life casting product images for quality inspection, with two classes: defective and OK. Images are loaded with data generators, resized to 224 × 224 pixels and rescaled to values between 0 and 1.
Model
A small TinyVGG-style CNN: stacked convolution and max-pooling layers, a flatten layer and a single sigmoid output for binary classification. It is trained with binary cross-entropy and the Adam optimizer for 5 epochs on a GPU.
Results
Validation accuracy rose from 79% after the first epoch to 94.8% after the fifth, with training accuracy at 96.7%. The notebook also shows random test images with the predicted class, outlined in green for OK and red for defective.
I evaluated on the validation split only. A held-out test set and a confusion matrix would be the next step before trusting it on a real line, because a missed defect costs more than a false alarm.
Credit
The base code follows the TensorFlow course by Andrei Neagoie (Zero To Mastery). I adapted it to this dataset.