how to train ai for defect recognition