Skip to content

Commit 7e070f2

Browse files
committed
Run pre-commit on all files
1 parent 0a9e9cf commit 7e070f2

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ venv/
8383
**/_version.py
8484

8585
# uv
86-
uv.lock
86+
uv.lock

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ recursive-exclude * __pycache__
66
recursive-exclude * *.py[co]
77
recursive-exclude docs *
88
recursive-exclude tests *
9+
recursive-exclude examples *
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
# Notes
44
# - all projects I tried are with a single video
55
# - in LP example project: no video directory
6-
# - sleap-io assumes frame paths have minimally: labeled-data/<video-name>/<img-name>.<ext>
7-
# <img-name> must contain the (sequence of) digits representing the frame index
8-
# if <img-name> is alphanumerical, the last sequence of digits is assumed to be the frame index
6+
# - sleap-io assumes frame paths have minimally:
7+
# labeled-data/<video-name>/<img-name>.<ext>
8+
# - <img-name> must contain the (sequence of) digits representing
9+
# the frame index
10+
# - if <img-name> is alphanumerical, the last sequence of digits is assumed to
11+
# be the frame index
912
# - when loading DLC files with sleap-io: the frames need to exist
1013

1114
# %%
1215
from pathlib import Path
1316

14-
from poseinterface.io import format_dlc_annotations_file
17+
from poseinterface.io import annotations_to_coco
1518

1619
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1720
# Input data: DLC project with a single video
@@ -24,7 +27,7 @@
2427
/ "DLC-openfield-Pranav-2018-10-30"
2528
/ "labeled-data"
2629
/ "m4s1"
27-
/ Path("CollectedData_Pranav.csv")
30+
/ "CollectedData_Pranav.csv"
2831
)
2932

3033
# Output path
@@ -37,8 +40,6 @@
3740
# %%%%%%%%%%%%
3841
# Export as COCO
3942

40-
out_json = format_dlc_annotations_file(
41-
dlc_annotations_files_csv, out_coco_json
42-
)
43+
out_json = annotations_to_coco(dlc_annotations_files_csv, out_coco_json)
4344

4445
# %%

poseinterface/io.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
from pathlib import Path
2+
23
import sleap_io as sio
34
from sleap_io.io import dlc
45

5-
66
_EMPTY_LABELS_ERROR_MSG = {
7-
"default": ("No annotations could be extracted from the input file."
8-
"Please check that the input file contains labeled frames."),
7+
"default": (
8+
"No annotations could be extracted from the input file."
9+
"Please check that the input file contains labeled frames."
10+
),
911
"dlc": (
1012
"Ensure that the paths to the labelled frames are in the "
1113
"standard DLC project format: "
1214
"labeled-data / <video-name> / "
1315
"<filename-with-frame-number>.<extension>"
1416
"and that the frames files exist."
15-
)
17+
),
1618
}
19+
20+
1721
def annotations_to_coco(
1822
input_path: Path,
1923
output_json_path: Path,
@@ -22,45 +26,46 @@ def annotations_to_coco(
2226
coco_visibility_encoding: str = "ternary",
2327
) -> Path:
2428
"""Export annotations file to COCO format.
25-
29+
2630
Parameters
27-
----------
31+
----------
2832
input_path : pathlib.Path
2933
Path to the input annotations file.
3034
output_json_path : pathlib.Path
3135
Path to save the output COCO JSON file.
3236
coco_image_filenames : str | list[str] | None, optional
33-
Optional image filenames to use in the COCO JSON. If provided,
34-
must be a single string (for single-frame videos) or a list of
35-
strings matching the number of labeled frames. If None (default),
37+
Optional image filenames to use in the COCO JSON. If provided,
38+
must be a single string (for single-frame videos) or a list of
39+
strings matching the number of labeled frames. If None (default),
3640
generates filenames from video filenames and frame indices.
3741
coco_visibility_encoding : str, optional
3842
Encoding scheme for keypoint visibility in the COCO JSON file.
3943
Options are "ternary" (0: not labeled, 1: labeled but not visible,
4044
2: labeled and visible) or "binary" (0: not visible, 1: visible).
4145
Default is "ternary".
42-
46+
4347
Returns
4448
-------
4549
pathlib.Path
4650
Path to the saved COCO JSON file.
47-
51+
4852
Notes
4953
-----
5054
The format of the input annotations file is automatically inferred based
51-
on its extension. See :func:`sleap_io.io.main.load_file` for supported formats.
55+
on its extension. See :func:`sleap_io.io.main.load_file` for supported
56+
formats.
5257
"""
5358
labels = sio.load_file(input_path)
5459
# Check if labels object is empty
5560
if len(labels.labeled_frames) == 0:
5661
error_msg = _EMPTY_LABELS_ERROR_MSG["default"]
5762
if dlc.is_dlc_file(input_path):
5863
error_msg += _EMPTY_LABELS_ERROR_MSG["dlc"]
59-
raise ValueError(error_msg)
64+
raise ValueError(error_msg)
6065
sio.save_coco(
6166
labels,
6267
output_json_path,
6368
image_filenames=coco_image_filenames,
64-
visibility_encoding=coco_visibility_encoding
69+
visibility_encoding=coco_visibility_encoding,
6570
)
6671
return output_json_path

0 commit comments

Comments
 (0)