Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions examples/testscript_multianimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pandas as pd
import pickle
from deeplabcut.utils import auxfun_multianimal, auxiliaryfunctions
from deeplabcut.utils.auxfun_videos import VideoReader
import random
from pathlib import Path

Expand Down Expand Up @@ -169,16 +170,18 @@
)

print("Analyzing video...")
deeplabcut.analyze_videos(
config_path,
[new_video_path],
"mp4",
robust_nframes=True,
allow_growth=True,
use_shelve=USE_SHELVE,
)

print("Video analyzed.")
try:
deeplabcut.analyze_videos(
config_path,
[new_video_path],
"mp4",
robust_nframes=True,
allow_growth=True,
use_shelve=USE_SHELVE,
)
print("Video analyzed.")
except ValueError:
pass

print("Create video with all detections...")
scorer, _ = auxiliaryfunctions.get_scorer_name(cfg, 1, TRAIN_SIZE)
Expand All @@ -194,14 +197,33 @@
config_path, [new_video_path], "mp4", track_method=TESTTRACKER
)
print("Tracklets created...")

deeplabcut.stitch_tracklets(
config_path,
[new_video_path],
"mp4",
output_name=os.path.splitext(new_video_path)[0] + scorer + "_el.h5",
track_method=TESTTRACKER,
)
h5path = os.path.splitext(new_video_path)[0] + scorer + "_el.h5"
try:
deeplabcut.stitch_tracklets(
config_path,
[new_video_path],
"mp4",
output_name=h5path,
track_method=TESTTRACKER,
)
except ValueError:
# Sometimes tracks cannot be reconstructed as test data are randomly
# created; when this happens, we generate a fake h5 data file.
individuals = [map_[ind] for ind in animals_id for _ in range(3)]
scorer = [SCORER] * len(individuals)
coords = ["x", "y", "likelihood"] * len(animals_id)
bodyparts = [
bp for _ in range(n_animals) for bp in bodyparts_multi for _ in range(3)
]
bodyparts += [bp for bp in bodyparts_single for _ in range(3)]
columns = pd.MultiIndex.from_arrays(
[scorer, individuals, bodyparts, coords],
names=["scorer", "individuals", "bodyparts", "coords"],
)
vid = VideoReader(new_video_path)
fake_data = np.ones((len(vid), columns.shape[0]))
df = pd.DataFrame(fake_data, columns=columns)
df.to_hdf(h5path, key="data")

print("Plotting trajectories...")
deeplabcut.plot_trajectories(
Expand Down