You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Huge inference time, GPU isn't used with maDLC and Pytorch #2975
I'm running my first maDLC model and I'm seeing terrible performance compared to the signle animal model.
It also seems as if the GPU is not properly engaged for maDLC.
On the same machine, analyzing a video with a single animal model has a speed of ~19it/sec and the resource monitor shows a stable activation of the GPU, but a maDLC model runs at 9sec/it (not a typo, it is really seconds per iteration) and the resource monitor shows only sporadic spikes in the GPU activity (see screenshot).
I tried different batch sizes (from 1 to 8), but that does not seem to be an issue here.
Steps To Reproduce
Activate single animal project and start video analysis to confirm GPU is properly activated
Switch to maDLC project
Choose video and start analysis
Observe terminal output and Nvidia resource monitor to see low performance
Relevant log output
# I have a few lines of code to double check cuda and the GPU are properly recognized, so I'll just paste the output here
(DEEPLABCUT) C:\Windows\System32>python -c "import torch; print('Torch version:', torch.__version__)"
Torch version: 2.5.1
(DEEPLABCUT) C:\Windows\System32>python -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('CUDA runtime:', torch.version.cuda); print('cuDNN version:', torch.backends.cudnn.version())"
CUDA available: True
CUDA runtime: 12.4
cuDNN version: 90100
(DEEPLABCUT) C:\Windows\System32>python -c "import deeplabcut; import torch; print('DLC GPU enabled:', torch.cuda.is_available())"
Loading DLC 3.0.0rc8...
DLC GPU enabled: True
Anything else?
I even tried the latest cuda version and the nightly build of pytorch that works with it, but same results
By "terrible performance" you mean the model doesn't detect the poses well? Okay you're reporting two different issues then.
Let's first focus on the speed and GPU engagement issue. Then we'll address the model performance issue once this is solved.
Could you please share the contents of your config.yaml and pytorch_config.yaml please (maDLC project, pytorch model, the one that doesn't work properly)?
Thank you very much for the detailed explanations.
I indeed can reproduce this issue when using your config files.
I also noticed that the evalutation stage (during training) shows the same behavior (GPU isn't used, and it takes a huge amount of time). Interestingly, the training process itself does use the GPU correctly, and is executed quite fast! What I also noticed that, during evaluation and video analysis, the RAM is getting crammed.
What seems special with your configs is that you have a lot of individuals (17), each with 29 bodyparts, plus also 34 unique bodyparts; I guess this is what brings out a potential issue in the processing pipeline.
At this point I don't know what is to blame, I'll continue investigating this.
You say that when using TensorFlow as engine - the inference time is decent and the GPU is properly used? Do you have as many individuals, bodyparts and unique bodyparts in your Tensorflow project too?
changed the title [-]Low performance with maDLC and pytorch (maDLC TF works fine)[/-][+]Huge inference time, GPU isn't used with maDLC and Pytorch[/+]on May 7, 2025
Hey,
great that you can reproduce the issue!
My tensorflow model was trained on the same data as the pytorch model, and uses the same bodyparts, unique bodyparts, and number of individuals.
After having letting it run now for a while, I noticed that the initial analysis speed drops down to 1.12it/s after 25h of analyzing the same video file.
Still faster than the 9s/it I got with pytorch though
Same config as yours but without the unique bodyparts
Same config as yours but half the number of individuals (8 instead of 17).
In both these cases the analysis time looks acceptable.
Then I tried with the original config again (17 individuals and unique bodyparts), the analysis takes ages (actually it seems to get stuck in my case).
Do you observe something similar on your side too?
The assembly is mostly based on the CPU, the computational costs scales in the number of detections (which is large when you have many individuals). Now, if your pose estimation is not well trained, then you get even more detections & poor costs, which will make the assembly step very slow (and most of the wall time will be spend on the CPU). Seems like in TF it works, how do the two models compare quantitatively (performance)?
So here are a few ideas:
try out DEKR, which does not rely on assembly methods.
make sure the pose estimation model doesn't give additional detections
consider pruning the graph for assembly (see Nature Methods paper)
Hey @AlexEMG, thanks for chiming in!
Here the performance of the two models
pytorch
Column1
Column2
%Training dataset
0.95
Shuffle number
2
Training epochs
170
Detector epochs (TD only)
-1
pcutoff
0.6
train rmse
31.52
train rmse_pcutoff
12.97
train mAP
28.51
train mAR
32.2
test rmse
41.01
test rmse_pcutoff
13.7
test mAP
23.48
test mAR
24.78
TensorFlow
Column1
Column2
0
Training iterations:
200000
%Training dataset
95
Shuffle number
1
Train error(px)
4.55
Test error(px)
14.71
p-cutoff used
0.6
Train error with p-cutoff
3.18
Test error with p-cutoff
13.3
I will look into DEKR and train up a model to test it, and I will also follow @maximpavliv advice and reduce the unique body parts (I can't reduce individuals unfortunately).
The DEKR model runs with 10-14 it/through the video file, but when it comes to saving the h5, it errors out.
INFO:console:E:\pig_overhead-TS-2025-03-12\videos\C31.20200324_150542_1.mp4
INFO:console:Loading From E:\pig_overhead-TS-2025-03-12\videos\C31.20200324_150542_1DLC_DekrW32_pig_overheadMar12shuffle3_snapshot_290.h5
100%|████████████████████████████████████████████████████████████████████████| 481250/481250 [05:57<00:00, 1347.68it/s]
INFO:console:The tracklets were created (i.e., under the hood deeplabcut.convert_detections2tracklets was run). Now you can 'refine_tracklets' in the GUI, or run 'deeplabcut.stitch_tracklets'.
INFO:console:Processing...
INFO:console:
INFO:console:E:\pig_overhead-TS-2025-03-12\videos\C31.20200324_150542_1.mp4
C:\Users\au783787\AppData\Local\anaconda3\envs\DLC_PY\lib\site-packages\deeplabcut\core\trackingutils.py:46: RuntimeWarning: invalid value encountered in scalar divide
return wh / (
The GUI still shows the progress bar moving, but I don't see any GPU or CPU activity.
In the folder I see four pickle files associated with the video, but no H5 file.
I have since the beginning of the issue reinstalled DLC in a new environment (because it did not like switching between TF and pytorch).
I now have a global installation of CUDA 12.8 (confirmed by nvidia-smi) and inside my environment I have reinstalled torch according to the official instruction pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128.
My environment also returns 2.7.0+cu128 for the torch version.
So far, when I had a mismatch between my cuda and TF or pytorch versions, the model completely refused to run on a GPU and fell back to CPU only, but I've never had it fail to assemble the h5 before.
Hi @tsievert, not sure if this was solved already. Are you still experiencing this issue with version 3.0.0rc13? I was just reading into this discussion and happy to assist in case this problem persists.
Activity
tsievert commentedon May 1, 2025
I have now trained a minimal TF model, and when I analyze the same video file with the TF model, I get good GPU engagement and 25-30it/sec.
So it seems as if the problem is pytorch exclusive
[-]Low performance with maDLC and pytorch[/-][+]Low performance with maDLC and pytorch (maDLC TF works fine)[/+]maximpavliv commentedon May 5, 2025
Hello,
By "terrible performance" you mean the model doesn't detect the poses well? Okay you're reporting two different issues then.
Let's first focus on the speed and GPU engagement issue. Then we'll address the model performance issue once this is solved.
Could you please share the contents of your config.yaml and pytorch_config.yaml please (maDLC project, pytorch model, the one that doesn't work properly)?
tsievert commentedon May 5, 2025
Sorry, bad phrasing on my end. I was referring to the slow speed of the analysis and not the quality of the analysis.
config.yaml
pytorch_config.yaml
maximpavliv commentedon May 7, 2025
Hello @tsievert,
Thank you very much for the detailed explanations.
I indeed can reproduce this issue when using your config files.
I also noticed that the evalutation stage (during training) shows the same behavior (GPU isn't used, and it takes a huge amount of time). Interestingly, the training process itself does use the GPU correctly, and is executed quite fast! What I also noticed that, during evaluation and video analysis, the RAM is getting crammed.
What seems special with your configs is that you have a lot of individuals (17), each with 29 bodyparts, plus also 34 unique bodyparts; I guess this is what brings out a potential issue in the processing pipeline.
At this point I don't know what is to blame, I'll continue investigating this.
You say that when using TensorFlow as engine - the inference time is decent and the GPU is properly used? Do you have as many individuals, bodyparts and unique bodyparts in your Tensorflow project too?
[-]Low performance with maDLC and pytorch (maDLC TF works fine)[/-][+]Huge inference time, GPU isn't used with maDLC and Pytorch[/+]tsievert commentedon May 7, 2025
Hey,
great that you can reproduce the issue!
My tensorflow model was trained on the same data as the pytorch model, and uses the same bodyparts, unique bodyparts, and number of individuals.
After having letting it run now for a while, I noticed that the initial analysis speed drops down to 1.12it/s after 25h of analyzing the same video file.
Still faster than the 9s/it I got with pytorch though
maximpavliv commentedon May 8, 2025
Hey, I tried a few experiments:
Same config as yours but without the unique bodyparts
Same config as yours but half the number of individuals (8 instead of 17).
In both these cases the analysis time looks acceptable.
Then I tried with the original config again (17 individuals and unique bodyparts), the analysis takes ages (actually it seems to get stuck in my case).
Do you observe something similar on your side too?
AlexEMG commentedon May 9, 2025
@tsievert -- please note that you use a bottom-up, two-stage models. The model predicts detections & costs, then the poses are assembled. See : https://www.nature.com/articles/s41592-022-01443-0
The assembly is mostly based on the CPU, the computational costs scales in the number of detections (which is large when you have many individuals). Now, if your pose estimation is not well trained, then you get even more detections & poor costs, which will make the assembly step very slow (and most of the wall time will be spend on the CPU). Seems like in TF it works, how do the two models compare quantitatively (performance)?
So here are a few ideas:
tsievert commentedon May 15, 2025
Hey @AlexEMG, thanks for chiming in!
Here the performance of the two models
pytorch
TensorFlow
I will look into DEKR and train up a model to test it, and I will also follow @maximpavliv advice and reduce the unique body parts (I can't reduce individuals unfortunately).
tsievert commentedon May 21, 2025
The DEKR model runs with 10-14 it/through the video file, but when it comes to saving the h5, it errors out.
The GUI still shows the progress bar moving, but I don't see any GPU or CPU activity.
In the folder I see four pickle files associated with the video, but no H5 file.
MMathisLab commentedon May 23, 2025
Perhaps back to an installation issue; given your CUDA version & pytorch version -- how did you install it?
CUDA runtime: 12.4for example, you need to be sure you install the correct pytorch for your CUDA version:
tsievert commentedon May 28, 2025
I have since the beginning of the issue reinstalled DLC in a new environment (because it did not like switching between TF and pytorch).
I now have a global installation of CUDA 12.8 (confirmed by
nvidia-smi) and inside my environment I have reinstalled torch according to the official instructionpip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128.My environment also returns
2.7.0+cu128for the torch version.So far, when I had a mismatch between my cuda and TF or pytorch versions, the model completely refused to run on a GPU and fell back to CPU only, but I've never had it fail to assemble the h5 before.
deruyter92 commentedon Dec 8, 2025
Hi @tsievert, not sure if this was solved already. Are you still experiencing this issue with version 3.0.0rc13? I was just reading into this discussion and happy to assist in case this problem persists.
tsievert commentedon Dec 11, 2025
Hey @deruyter92 , thanks for checking in!
I think the issue was related to #3108 in the end. At the moment I am running maDLC with this branch https://github.com/DeepLabCut/DeepLabCut/tree/maxim/fix_shelf_writer without any issue.