02 · Machine Learning for Manufacturing

Casting Defect
Inspection System

Independent project, built solo · Python / PyTorch · github.com/raghavsingh1234

Visual inspection of cast parts is slow and inconsistent between operators, and a missed defect is expensive downstream. I wanted to see whether a single photo of a part could be turned into a reliable accept-or-reject call, with a visual the inspector could actually trust. I built the whole thing end to end: the data pipeline, the model, the explainability layer, and the dashboard it runs in.

What I built

Everything, on my own. I assembled and cleaned the dataset, wrote the two-stage transfer-learning training in PyTorch, added Grad-CAM so each prediction shows what the model reacted to, and deployed it as a Streamlit dashboard that takes an image upload and returns a class, a confidence, and a disposition. Trained on Google Colab.

Inspection dashboard: original image, Grad-CAM heatmap, and results panel
FIG 1 · The dashboard. Left: input casting. Centre: Grad-CAM activation, concentrated on the surface flaw rather than the background or part edges. Right: class, confidence, and disposition.
Model data
TaskBinary classification, defective or acceptable
Dataset7,000+ labeled cast-metal images (public)
BackboneResNet18, ImageNet pretrained
TrainingTwo-stage: frozen backbone, then unfrozen final block
Test accuracy96%
ExplainabilityGrad-CAM class activation maps
StackPython · PyTorch · Streamlit · Colab (T4)
Design decisions
02 · Machine Learning · continued

Where It
Got Hard

The problem the classifier couldn't solve, and what I did instead

The classifier itself worked. The harder problem was grading how defective a part is, so borderline parts could be triaged instead of scrapped. That turned out to be the real engineering of the project, and it did not go the way I first expected.

Challenges