How to detect defects with AI