AB.Visual inspection becomes stronger when consistency can be measured.All projects

Data Science

Casting Defect Detection

A CNN image-classification workflow for identifying defective industrial castings from visual inspection data.

TensorFlow / KerasCNNImage ClassificationModel Evaluation
View source repository
Casting Defect Detection interface

Why it matters

Shows how deep-learning classification can support faster and more consistent manufacturing quality checks.

My role

Computer-vision practitioner

  1. 01Built a consistent grayscale image pipeline with 128×128 resizing and pixel normalization for training and single-image inference.
  2. 02Developed a compact regularized CNN with augmentation, convolution/pooling blocks, dropout, sigmoid output, and early stopping.
  3. 03Evaluated the classifier on validation and held-out test data and packaged reusable prediction and model-saving workflows.
01

Situation

Manual visual inspection of aluminium castings is inconsistent and slow, and manufacturing teams need a fast first-pass check that can flag likely defects for review.

02

Task

Build a binary image classifier that distinguishes defective casting fronts from acceptable parts, with a preprocessing and inference pipeline consistent enough to trust on new images.

03

Action

  • Images from def_front and ok_front folders are converted to one-channel grayscale, resized to 128×128, normalized to the [0,1] range, and split into train, validation, and test sets.
  • A compact Keras CNN applies optional random flips and rotations, repeated Conv2D/MaxPooling2D blocks, dropout regularization, and a sigmoid output, trained with Adam and binary cross-entropy, with early stopping on validation loss.
  • Training curves, held-out test loss, a confusion matrix, and a full classification report assess overall performance and class balance rather than a single accuracy number.
  • A single-image inference helper applies the identical grayscale, resize, and normalization pipeline and returns the predicted class and defect probability, with the trained model saved for reuse without retraining.
04

Result

The final model reached approximately 95% validation accuracy and 96% test accuracy, with precision and recall between 0.93 and 0.96 across both defective and acceptable classes.

Technical implementation

How the solution was built.

Each layer connects an implementation choice to the decision or workflow it supports.

06 layers
LayerImplementationOperational purpose
Image pipelineGrayscale conversion, 128 by 128 resizing and pixel normalizationApply identical preprocessing during training and inference
Data splitSeparate training, validation and held-out test datasetsTune the workflow without contaminating final evaluation evidence
AugmentationControlled random flips and rotationsImprove robustness to small visual variations in part orientation
CNN architectureConv2D, MaxPooling2D, dense layers, dropout and sigmoid binary outputLearn local defect patterns with a compact laptop-trainable model
Training controlAdam, binary cross-entropy and early stopping on validation lossOptimize classification while limiting overfitting
Evaluation and reuseConfusion matrix, classification report, single-image prediction and saved model artifactsVerify class-level performance and support repeatable inference