Optimizing ML algorithms for image analysis