A CNN flags defective castings, explains itself with Grad-CAM, picks its decision threshold from the cost of a shipped defect versus a false reject, and is tested for whether it really looks at the part or at how the photos were taken. The model below runs entirely in your browser.
A model that reads the part keeps its AP with the background greyed out or its brightness equalised, and falls to chance (AP = defect share) when only the background is visible.