Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Oct 19, 2023
1 parent 12e05ff commit b482d53
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 91 deletions.
21 changes: 11 additions & 10 deletions sleap/io/format/deeplabcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def read_frames(
Instance(
skeleton=skeleton,
points=instance_points,
track=tracks.get(animal_name, None),
track=tracks[animal_name],
)
)
else:
Expand Down Expand Up @@ -312,22 +312,23 @@ def read(

shortname = os.path.split(data_subdir)[-1]
video_path = None
with os.scandir(videos_dir) as file_iterator:
for file in file_iterator:
if not file.is_file():
continue
if os.path.splitext(file.name)[0] != shortname:
continue
video_path = os.path.join(videos_dir, file.name)
break
if os.path.exists(videos_dir):
with os.scandir(videos_dir) as file_iterator:
for file in file_iterator:
if not file.is_file():
continue
if os.path.splitext(file.name)[0] != shortname:
continue
video_path = os.path.join(videos_dir, file.name)
break

if video_path is not None and os.path.exists(video_path):
video = Video.from_filename(video_path)
else:
# When no video is found, the individual frame images
# stored in the labeled data subdir will be used.
if video_path is None:
video_path = os.path.join(videos_dir, f"{shortname}.[EXT]")
video_path = os.path.join(videos_dir, f"{shortname}.mp4")
print(
f"Unable to find {video_path} so using individual frame images."
)
Expand Down
14 changes: 7 additions & 7 deletions tests/data/dlc/labeled-data/video/CollectedData_LM.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
scorer,,,LM,LM,LM,LM,LM,LM,LM,LM,LM,LM,LM,LM
individuals,,,individual1,individual1,individual1,individual1,individual1,individual1,individual2,individual2,individual2,individual2,individual2,individual2
bodyparts,,,A,A,B,B,C,C,A,A,B,B,C,C
coords,,,x,y,x,y,x,y,x,y,x,y,x,y
labeled-data,video,img000.png,0,1,2,3,4,5,6,7,8,9,10,11
labeled-data,video,img001.png,12,13,,,15,16,17,18,,,20,21
scorer,,,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer,Scorer
individuals,,,Animal1,Animal1,Animal1,Animal1,Animal1,Animal1,Animal2,Animal2,Animal2,Animal2,Animal2,Animal2,single,single,single,single
bodyparts,,,A,A,B,B,C,C,A,A,B,B,C,C,D,D,E,E
coords,,,x,y,x,y,x,y,x,y,x,y,x,y,x,y,x,y
labeled-data,video,img000.png,0,1,2,3,4,5,6,7,8,9,10,11,,,,
labeled-data,video,img001.png,12,13,,,15,16,17,18,,,20,21,22,23,24,25
labeled-data,video,img002.png,,,,,,,,,,,,
labeled-data,video,img003.png,22,23,24,25,26,27,,,,,,
labeled-data,video,img003.png,26,27,28,29,30,31,,,,,,,32,33,34,35
8 changes: 5 additions & 3 deletions tests/data/dlc/madlc_230_config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Project definitions (do not edit)
Task: madlc_2.3.0
Task: maudlc_2.3.0
scorer: LM
date: Mar1
multianimalproject: true
identity: false

# Project path (change when moving around)
project_path: D:\social-leap-estimates-animal-poses\pull-requests\sleap\tests\data\dlc\madlc_testdata_v3
project_path: D:\social-leap-estimates-animal-poses\pull-requests\sleap\tests\data\dlc\maudlc_testdata_v3

# Annotation data set configuration (and individual video cropping parameters)
video_sets:
Expand All @@ -16,7 +16,9 @@ individuals:
- individual1
- individual2
- individual3
uniquebodyparts: []
uniquebodyparts:
- D
- E
multianimalbodyparts:
- A
- B
Expand Down
67 changes: 0 additions & 67 deletions tests/data/dlc/maudlc_230_config.yaml

This file was deleted.

7 changes: 3 additions & 4 deletions tests/io/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def test_matching_adaptor(centered_pair_predictions_hdf5_path):
[
"tests/data/dlc/labeled-data/video/madlc_testdata.csv",
"tests/data/dlc/labeled-data/video/madlc_testdata_v2.csv",
"tests/data/dlc/madlc_230_config.yaml",
],
)
def test_madlc(test_data):
Expand Down Expand Up @@ -237,7 +236,7 @@ def test_madlc(test_data):
[
"tests/data/dlc/labeled-data/video/maudlc_testdata.csv",
"tests/data/dlc/labeled-data/video/maudlc_testdata_v2.csv",
"tests/data/dlc/maudlc_230_config.yaml",
"tests/data/dlc/madlc_230_config.yaml",
],
)
def test_maudlc(test_data):
Expand Down Expand Up @@ -288,14 +287,14 @@ def test_maudlc(test_data):
[[26, 27], [28, 29], [30, 31], [np.nan, np.nan], [np.nan, np.nan]],
)
assert_array_equal(
labels[2][0].numpy(),
labels[2][1].numpy(),
[[np.nan, np.nan], [np.nan, np.nan], [np.nan, np.nan], [32, 33], [34, 35]],
)
assert labels[2].frame_idx == 3

# Assert tracks are correct
assert len(labels.tracks) == 3
assert set(t.name for t in labels.tracks) == set(["Animal1", "Animal1", "single"])
assert sorted([t.name for t in labels.tracks]) == sorted(["Animal1", "Animal2", "single"])
for t in labels.tracks:
if t.name == "single":
assert t.spawned_on == 1
Expand Down

0 comments on commit b482d53

Please sign in to comment.