Skip to content

analyze_videos (PyTorch): OverflowError in _generate_output_data when a video yields zero detections (empty predictions) #3485

Description

@MathieuN6

Is there an existing issue for this?

  • I have searched the existing issues

Operating System

Windows 11 and Linux

DeepLabCut version

3.0.0rc13

What engine are you using?

pytorch

DeepLabCut mode

single animal

Device type

NVIDIA Geforce RTX 4070 Laptop GPU (windows 11)
NVIDIA RTX 2000 Ada Generation (Linux)

Bug description 🐛

With the PyTorch engine (top-down: detector + pose), deeplabcut.analyze_videos crashes with OverflowError: cannot convert float infinity to integer when a video produces no detections on any frame, so the predictions list is empty.

In _generate_output_data, the key width is computed as:

deeplabcut/pose_estimation_pytorch/apis/videos.py (v3.0.0rc13, line 903)

str_width = int(np.ceil(np.log10(len(predictions))))

When len(predictions) == 0, np.log10(0) = -inf and int(np.ceil(-inf)) raises OverflowError, aborting the whole analyze_videos call.

This happens legitimately whenever a clip contains no animal the detector recognizes (e.g. a setup/handling segment recorded before the actual trial). The empty-predictions condition is even detected just upstream, in video_inference:

same file, ~lines 232-240

if shelf_writer is None and len(predictions) != n_frames:
logging.warning(
f"The video metadata indicates that there {n_frames} in the video, but "
f"only {len(predictions)} were able to be processed. This can happen if "
"the video is corrupted. ..."
)

…but it is only warned about, not guarded against downstream, so the run still crashes.

Steps To Reproduce

  1. A top-down PyTorch project (e.g. fasterrcnn_mobilenet_v3_large_fpn detector + HRNet pose).
  2. Run deeplabcut.analyze_videos(config, [video], shuffle=N) on a video in which the animal is absent (or simply never detected).
  3. The detector and pose progress bars both run over all N frames, then the "only 0 were able to be processed" warning is logged, immediately followed by the crash.

Relevant log output

OverflowError: cannot convert float infinity to integer
2026-09-07 11:38:53 ERROR Abandon de droite_GX010420.MP4 après 2 tentative(s)
2026-09-07 11:38:53 INFO DeepLabCut : analyse de 1 vidéo(s) [shuffle=3] (.h5 à côté des vidéos)
2026-09-07 11:39:32 ERROR Crash DLC (coupable probable : gauche_GX010606.MP4)
Traceback (most recent call last):
  File "/home/Documents/workspaces/bar_test/pipeline_deeplabcut/run_inference.py", line 104, in analyze_with_retries
    analyze_with_dlc(config, batch, destfolder, batch_size, detector_batch_size,
  File "/home/mlalaque/Documents/workspaces/bar_test/pipeline_deeplabcut/run_inference.py", line 67, in analyze_with_dlc
    deeplabcut.analyze_videos(
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/utils/deprecation.py", line 198, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/utils/deprecation.py", line 198, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/compat.py", line 973, in analyze_videos
    return analyze_videos(
           ^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/utils/deprecation.py", line 198, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py", line 612, in analyze_videos
    output_data = _generate_output_data(pose_cfg, predictions)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miniconda3/envs/dlc/lib/python3.12/site-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py", line 898, in _generate_output_data
    str_width = int(np.ceil(np.log10(len(predictions))))

Anything else?

Even though the error is not that problematic since it is triggered by videos with no mouse that could or should be skipped, the current warning is misleading and points at video corruption.

Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpytorch

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions