Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions deeplabcut/gui/tabs/create_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def create_videos(self):
):
bodyparts = self.bodyparts_to_use

deeplabcut.create_labeled_video(
videos_created = deeplabcut.create_labeled_video(
config=config,
videos=videos,
shuffle=shuffle,
Expand All @@ -228,7 +228,14 @@ def create_videos(self):
trailpoints=trailpoints,
color_by=color_by,
)
self.root.writer.write("Labeled videos created.")
if all(videos_created):
self.root.writer.write("Labeled videos created.")
else:
failed_videos = [
video for success, video in zip(videos_created, videos) if not success
]
failed_videos_str = ", ".join(failed_videos)
self.root.writer.write(f"Failed to create videos from {failed_videos_str}.")

if self.plot_trajectories.checkState():
deeplabcut.plot_trajectories(
Expand Down
15 changes: 12 additions & 3 deletions deeplabcut/utils/make_labeled_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ def create_labeled_video(

Returns
-------
None
results : list[bool]
``True`` if the video is successfully created for each item in ``videos``.

Examples
--------
Expand Down Expand Up @@ -549,7 +550,7 @@ def create_labeled_video(
Videos = auxiliaryfunctions.get_list_of_videos(videos, videotype)

if not Videos:
return
return []

func = partial(
proc_video,
Expand Down Expand Up @@ -577,9 +578,10 @@ def create_labeled_video(
)

with Pool(min(os.cpu_count(), len(Videos))) as pool:
pool.map(func, Videos)
results = pool.map(func, Videos)

os.chdir(start_path)
return results


def proc_video(
Expand Down Expand Up @@ -612,6 +614,10 @@ def proc_video(
----------


Returns
-------
result : bool
``True`` if a video is successfully created.
"""
videofolder = Path(video).parents[0]
if destfolder is None:
Expand All @@ -632,6 +638,7 @@ def proc_video(

if os.path.isfile(videooutname1) or os.path.isfile(videooutname2):
print("Labeled video {} already created.".format(vname))
return True
else:
print("Loading {} and data.".format(video))
try:
Expand Down Expand Up @@ -735,9 +742,11 @@ def proc_video(
trailpoints=trailpoints,
fps=outputframerate,
)
return True

except FileNotFoundError as e:
print(e)
return False


def _create_labeled_video(
Expand Down
52 changes: 29 additions & 23 deletions deeplabcut/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def plot_trajectories(
)
return

failed = []
failures, multianimal_errors = [], []
for video in Videos:
if destfolder is None:
videofolder = str(Path(video).parents[0])
Expand All @@ -287,7 +287,6 @@ def plot_trajectories(
df, _, _, suffix = auxiliaryfunctions.load_analyzed_data(
videofolder, vname, DLCscorer, filtered, track_method
)
failed.append(False)
tmpfolder = os.path.join(videofolder, "plot-poses", vname)
auxiliaryfunctions.attempttomakefolder(tmpfolder, recursive=True)
# Keep only the individuals and bodyparts that were labeled
Expand Down Expand Up @@ -315,32 +314,39 @@ def plot_trajectories(
linewidth=linewidth,
)
except FileNotFoundError as e:
failed.append(True)
print(e)
try:
_ = auxiliaryfunctions.load_detection_data(
video, DLCscorer, track_method
)
print(
'Call "deeplabcut.stitch_tracklets()"'
" prior to plotting the trajectories."
)
except FileNotFoundError as e:
print(e)
print(
f"Make sure {video} was previously analyzed, and that "
f'detections were successively converted to tracklets using "deeplabcut.convert_detections2tracklets()" '
f'and "deeplabcut.stitch_tracklets()".'
)

if not all(failed):
failures.append(video)
if track_method != "":
# In a multi animal scenario, show more verbose errors.
try:
_ = auxiliaryfunctions.load_detection_data(
video, DLCscorer, track_method
)
error_message = 'Call "deeplabcut.stitch_tracklets() prior to plotting the trajectories.'
except FileNotFoundError as e:
print(e)
error_message = (
f"Make sure {video} was previously analyzed, and that "
"detections were successively converted to tracklets using "
'"deeplabcut.convert_detections2tracklets()" and "deeplabcut.stitch_tracklets()".'
)
multianimal_errors.append(error_message)

if len(failures) > 0:
# Some vidoes were not evaluated.
failed_videos = ",".join(failures)
if len(multianimal_errors) > 0:
verbose_error = ": " + " ".join(multianimal_errors)
else:
verbose_error = "."
print(
'Plots created! Please check the directory "plot-poses" within the video directory'
f"Plots could not be created for {failed_videos}. "
f"Videos were not evaluated with the current scorer {DLCscorer}"
+ verbose_error
)
else:
print(
f"Plots could not be created! "
f"Videos were not evaluated with the current scorer {DLCscorer}."
'Plots created! Please check the directory "plot-poses" within the video directory'
)


Expand Down