Skip to content

PyTorch maDLC analysis crashes post-inference with ValueError: need at least one array to stack #3108

Closed

Description

@tsievert

Is there an existing issue for this?

  • I have searched the existing issues

Operating System

AlmaLinux 9.6 (Sage Margay) (HPC)

DeepLabCut version

3.0rc10/rc12

What engine are you using?

pytorch

DeepLabCut mode

multi animal

Device type

Nvidia L40S 48GB

Bug description 🐛

After training up a PyTorch model, I ran the analysis step in order to extract outlier frames.
The analysis step run to 100% and then threw an error.

100%|██████████| 1296914/1296914 [15:18:47<00:00, 23.53it/s]

Traceback (most recent call last):
  File "/home/ts/scripts/DLC_analyze_and_extract.py", line 71, in <module>
    sys.exit(main())
  File "/home/ts/scripts/DLC_analyze_and_extract.py", line 37, in main
    deeplabcut.analyze_videos(
  File "/home/ts/miniforge3/envs/dlc/lib/python3.12/site-packages/deeplabcut/compat.py", line 953, in analyze_videos
    return analyze_videos(
  File "/home/ts/miniforge3/envs/dlc/lib/python3.12/site-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py", line 689, in analyze_videos
    _generate_assemblies_file(
  File "/home/ts/miniforge3/envs/dlc/lib/python3.12/site-packages/deeplabcut/pose_estimation_pytorch/apis/videos.py", line 883, in _generate_assemblies_file
    unique_bpts = np.stack(keypoint_preds[num_bodyparts:])
  File "/home/ts/miniforge3/envs/dlc/lib/python3.12/site-packages/numpy/core/shape_base.py", line 445, in stack
    raise ValueError('need at least one array to stack')

ValueError: need at least one array to stack

I tried with both autotrack = true and false, tried stitching the tracklets after the analysis.
All resulted in the same error.
Even a short 2 minute clip caused the same error.

With some trial and error I figured out that the _full.pickle file is not written, but the _full.pickle.dat, _full.pickle.dir, _full.pickle.bak, and _meta.pickle exist.

Steps To Reproduce

  1. Train pytorch model
  2. run analysis
  3. see failure once 100% is reached
  4. No _full.pickle

Relevant log output

Anything else?

Tried it both with rc10 and rc12, both with the same error.
Also both dekr_w48 and dlcrnet_stride32_ms5 show the same behavior.
Pytorch is 2.8.0+cu128

I can share a reproducible example via email with a 2 min video.

Code of Conduct

Activity

  1. maximpavliv commented on Oct 1, 2025

    @maximpavliv
    Contributor

    Hi @tsievert ,

    Thanks for the detailed report and for trying both rc10/rc12 and different backbones — that’s useful context.

    The error you’re seeing:

    unique_bpts = np.stack(keypoint_preds[num_bodyparts:])
    ValueError: need at least one array to stack
    

    means that the slice keypoint_preds[num_bodyparts:] is empty, so there are no arrays to combine. In practice this usually points to an issue with the predicted unique bodyparts: either no detections were produced beyond the number of “individual” bodyparts, or the assembly step doesn’t find anything to stack.

    This could happen if:

    • All detections for some (or all) unique bodyparts are empty,
    • The number of bodyparts specified in the config doesn’t match what the model was trained to predict,
    • Or there’s a mismatch between the project configuration and the model configuration.

    Could you check if there’s any reason on your side why the model might not be producing predictions for those bodyparts? If not, the best next step would be to share:

    1. Your project’s config.yaml (from the project folder), and
    2. Your model’s pytorch_config.yaml (from the shuffle folder).

    That will help us reproduce and see if the mismatch comes from the config or from the analysis pipeline.

  2. added
    more-data-requested-by-us
    on Oct 1, 2025
  3. tsievert commented on Oct 1, 2025

    @tsievert
    Author

    Hey @maximpavliv,

    from what I can see from the model evaluation, the unique bodyparts are detected decently, and I don't spot a mismatch between the configs.
    Here are the two requested files

    config.yaml
    pytorch_config.yaml

  4. maximpavliv commented on Oct 1, 2025

    @maximpavliv
    Contributor

    Thanks for sharing the configs — I also don’t see a mismatch there, so things look consistent on that front.

    To move forward, it would be very helpful if you could provide a minimal reproducible example. For instance, a short video (like the 2-minute one you mentioned) along with the corresponding project folder that triggers the error would let us investigate directly. If possible, please share it via Google Drive, WeTransfer, or a similar service, and post the link here (or send it privately if needed).

    That way we can try to reproduce the exact error and pinpoint whether it’s coming from the analysis step itself or from the specific data/model combination.

  5. tsievert commented on Oct 1, 2025

    @tsievert
    Author

    Could you tell me to which email I could send the link? I'm not aware of a DM function in Github

  6. maximpavliv commented on Oct 1, 2025

    @maximpavliv
    Contributor

    You can send it to my email address: [email protected]

  7. tsievert commented on Oct 2, 2025

    @tsievert
    Author

    After some reflection, this seems similar to what I reported here #2975 (comment)
    The main difference are the other issue was on a Windows system, while this issue is on a Linux HPC.
    But both issues are with the same data and config.
    The other issue relied on using the GUI, this issue runs headless.

  8. tsievert commented on Oct 2, 2025

    @tsievert
    Author

    Quick update, the error persists with rc13

  9. maximpavliv commented on Oct 2, 2025

    @maximpavliv
    Contributor

    Thanks for the update @tsievert .

    I managed to reproduce the issue with the data you sent me. I will investigate this further next week, I'll keep you posted.

    Best,
    Maxim

  10. removed
    more-data-requested-by-us
    on Oct 2, 2025
  11. maximpavliv commented on Oct 6, 2025

    @maximpavliv
    Contributor

    Hi @tsievert ,

    Thank you for your detailed report and for taking the time to trace the issue — feedback like this really helps us improve DeepLabCut! 🙏

    I’ve opened a Pull Request (#3112) that fixes the problem you identified. The bug was caused by unique_bodyparts and identity_scores being overwritten with None inside ShelfWriter.add_prediction().

    You can already test the fix by installing DeepLabCut from my fix branch, or simply wait for the PR to be merged — the update should be included in the next release shortly.

    Thanks again for helping make DLC better! 🚀

  12. tsievert commented on Oct 7, 2025

    @tsievert
    Author

    Hey @maximpavliv,
    Thank you so much for the fix!

    I can confirm that the branch seems to work as intended.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions