Detections
- byotrack.api.detector.detections.sorted_alphanumeric(data: Iterable[str])
Sorts alphanumeriacally an iterable of strings
“1” < “2” < “10” < “foo1” < “foo2” < “foo3”
- byotrack.api.detector.detections.relabel_consecutive(segmentation: Tensor) Tensor
Relabel a segmentation mask so that labels are consecutives
For N instances, labels are 0 for background and then [1:N] for each instance.
- Parameters:
segmentation (torch.Tensor) – Segmentation mask Shape: (H, W), dtype: int32
- Returns:
The same segmentation mask where labels are consecutive (from 0 to N)
- Return type:
torch.Tensor
- class byotrack.api.detector.detections.Detections(data: Dict[str, Tensor], frame_id: int = -1)
Bases:
objectDetections for a given frame
Built from a data dict. The data has to contained one of “position”, “bbox” or “segmentation” keys that respectively define the positions of instances center (i, j), the bounding boxes of instances (top, left, height, width) or the instance segmentation of the image (H, W).
Positions are stored as floats (row first). Bounding boxes are stored as ints (row first), thus right = left + width - 1 The labels of the segmentation mask have to be consecutive. You can make it consecutive using relabel_consecutive.
Additional optional data is also expected like “confidence” or “shape” that respectively defines the confidence for each detection and the shape of the image (H, W).
Any additional meta information on the detections can be also given.
Defines position, bbox, segmentation, and confidence properties. Each of them are either from the data or extrapolated if missing (see _extrapolate_xxx).
- shape
(Tuple[int, int]): Shape of the image (H, W). (Extrapolated if not given)
- position
Positions (i, j) of instances (center) inferred from the data Shape: (N, 2), dtype: float32
- Type:
torch.Tensor
- bbox
Bounding boxes of instances inferred from the data Shape: (N, 4), dtype: int32
- Type:
torch.Tensor
- segmentation
Segmentation inferred from the data Shape: (H, W), dtype: int32
- Type:
torch.Tensor
- confidence
Confidence for each instance Shape: (N,), dtype: float32
- Type:
torch.Tensor
- save(path: str | PathLike) None
Save detections to a file using torch.save
- Parameters:
path (str | os.PathLike) – Output path
- static load(path: str | PathLike) Detections
Load a detections for a given frame using torch.load
- Parameters:
path (str | os.PathLike) – Input path
- static save_multi_frames_detections(detections_sequence: Collection[Detections], path: str | PathLike) None
Save detections for a sequence of frames
It will save the detections as:
path/{frame_id}.pt ...
- Parameters:
detections_sequence (Collection[Detections]) – Detections for each frame Each detections should have a different frame_id
path (str | os.PathLike) – Output folder
- static load_multi_frames_detections(path: str | PathLike) Collection[Detections]
Load detections for a sequence of frames
Expect the following file structure:
path/{frame_id}.pt ...
- Parameters:
path (str | os.PathLike) – Input folder
- Returns:
Detections for each frame (sorted by frame id)
- Return type:
Collection[Detections]