def fastface_collate_fn(samples: Sequence[Dict[str, Any]]) -> Dict[str, Sequence[Any]]:
    """Collate function from fastface.

    Organizes individual elements in a batch, calls prepare_batch from fastface and prepares the targets.

    """
    samples = {key: [sample[key] for sample in samples] for key in samples[0]}

    images, scales, paddings = ff.utils.preprocess.prepare_batch(samples[DataKeys.INPUT], None, adaptive_batch=True)

    samples["scales"] = scales
    samples["paddings"] = paddings

    if DataKeys.TARGET in samples:
        targets = samples[DataKeys.TARGET]

        for i, (target, scale, padding) in enumerate(zip(targets, scales, paddings)):
            target["target_boxes"] *= scale
            target["target_boxes"][:, [0, 2]] += padding[0]
            target["target_boxes"][:, [1, 3]] += padding[1]
            targets[i]["target_boxes"] = target["target_boxes"]

        samples[DataKeys.TARGET] = targets
    samples[DataKeys.INPUT] = images

    return samples
Collate function from fastface.

    Organizes individual elements in a batch, calls prepare_batch from fastface and prepares the targets.

    
src/flash/image/face_detection/input_transform.py