A Flexible Framework for Learning Visual Quality Inspection by