Coverage for collectra/tasks/object_detection/batching.py: 100.00%

6 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 04:26 +0000

1"""Helpers shared by detectors that predict over many images in one batch.""" 

2 

3from __future__ import annotations 

4 

5from collectra.types.images import Image, ImageCrop 

6 

7 

8def image_cache_key(image: Image, *settings) -> tuple: 

9 """Identify the pixels (and settings) a cached prediction was made for.""" 

10 parent = getattr(image, "source_parent", None) 

11 crop = ( 

12 (image.x_center, image.y_center, image.width_relative, image.height_relative) 

13 if isinstance(image, ImageCrop) 

14 else None 

15 ) 

16 return ( 

17 str(image.get_path()), 

18 crop, 

19 image.orientation, 

20 image_cache_key(parent) if parent is not None else None, 

21 *settings, 

22 )