Several photographs of one sample can share distinctive backgrounds and construction details. Distributing them casually across evaluation folds can make a model appear more general than it is.
Scikit-learn provides grouped cross-validation strategies that keep groups separated between training and evaluation. Scikit-learn — cross validation.
Define a meaningful group
Depending on the task, a group may be a physical item, production lot or another linked unit. Choose the boundary around the intended generalisation question, not around whichever field is easiest to export.

Audit the split
Check that related records actually follow the grouping rule. A correctly named group column is not evidence that image duplicates or copied identifiers have been resolved. Report what remained unseen in each evaluation.

Source reviewed 25 October 2026. Interpretation and original diagrams: PLUSHIP / Qunhe. Examples are illustrative.
Related reading
An Unusual Image Is Not Automatically a Defective Product
Instance Masks Separate Individual Objects in a Product Photograph
