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

Industrial objective

The binary classifier distinguishes defective aluminium casting fronts from acceptable parts, framing computer vision as a first-pass manufacturing quality-control assistant.

02

Image preparation

Images are loaded from def_front and ok_front folders, converted to one-channel grayscale, resized to 128×128, normalized to the [0,1] range, and split into train, validation, and test datasets.

03

CNN approach

The compact Keras model uses optional random flips and rotations, repeated Conv2D and MaxPooling2D blocks, dense layers, dropout regularization, and a sigmoid output trained with Adam and binary cross-entropy.

04

Evaluation

Training curves, validation loss, held-out test loss, confusion matrix, classification report, precision, recall, and F1 assess both overall performance and class balance. Early stopping limits overfitting.

05

Results

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

06

Reusable inference

A single-image helper applies the same grayscale, resize, and normalization pipeline, returns the predicted class and defect probability, and the trained model is saved for reuse without retraining.

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