Skip to content

Conversation

@n-poulsen
Copy link
Contributor

When there aren't enough tracks found by the stitcher, the current implementation fails. By running

deeplabcut.analyze_videos(
    "project/config.yaml", ["/videos/"], videotype='.avi', auto_track=True, n_tracks=10,
)

The following error occurs as remaining_nodes is an empty list

deeplabcut/refine_training_dataset/stitch.py:690: UserWarning: No optimal solution found. Employing black magic...
Traceback (most recent call last):
  File "deeplabcut/refine_training_dataset/stitch.py", line 687, in stitch
    _, self.flow = nx.capacity_scaling(self.G)
  File "/lib/python3.9/site-packages/networkx/algorithms/flow/capacityscaling.py", line 394, in capacity_scaling
    raise nx.NetworkXUnfeasible("No flow satisfying all demands.")
networkx.exception.NetworkXUnfeasible: No flow satisfying all demands.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "deeplabcut/refine_training_dataset/stitch.py", line 755, in stitch
    self.build_graph(list(remaining_nodes), max_gap=np.inf)
  File "deeplabcut/refine_training_dataset/stitch.py", line 644, in build_graph
    nodes_in, nodes_out = zip(
ValueError: not enough values to unpack (expected 2, got 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "deeplabcut/pose_estimation_tensorflow/predict_videos.py", line 651, in analyze_videos
    stitch_tracklets(
  File "deeplabcut/refine_training_dataset/stitch.py", line 1201, in stitch_tracklets
    stitcher.stitch()
  File "deeplabcut/refine_training_dataset/stitch.py", line 766, in stitch
    raise ValueError(
ValueError: Could not reconstruct 10 tracks from the tracklets given.

This PR simply returns once there are no remaining nodes, even if the number of tracks found is smaller than the desired number of tracks (as if there are no remaining nodes, no new tracks can be found). To keep the shape of the output dataframe identical to when tracks are found for all individuals, NaN-filled columns are added for the missing tracks. A user warning is printed so the user is informed that not all tracks were found:

deeplabcut/refine_training_dataset/stitch.py:763: UserWarning: Only 4 tracks could be reconstructed.

@n-poulsen n-poulsen requested a review from jeylau June 13, 2023 07:27
self.G.nodes["sink"]["demand"] = incomplete_tracks
_, self.flow = nx.capacity_scaling(self.G)
paths += self.reconstruct_paths()
if len(remaining_nodes) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! By the way, I checked, and we could also have:

if not remaining_nodes:
    return

as the finally clause is executed before the function exits, no matter what.
But that's a detail 😃

Copy link
Contributor

@jeylau jeylau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@MMathisLab MMathisLab merged commit 278590e into DeepLabCut:main Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants