Improving accuracy of automatic optical inspection with machine learning