Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Operating System
Windows 11 Pro
DeepLabCut version
3.0.0rc9
What engine are you using?
pytorch
DeepLabCut mode
multi animal
Device type
Intel(R) Core(TM) i9-14900HX (2.20 GHz)
Bug description 🐛
After training previous multi-animal projects successfully on DLC 2.3.5, I created a project on a new device with DLC 3.0 and successfully progressed to training the new network. As we intend to use this pose estimation for later analysis in SimBA, we were encouraged to manually label ~1000 images (33 per video from 32 videos). We trained the network for 950 epochs on a batch size of 8 (further details below), but evaluation of the network displayed awful results, and the tracklets were empty during analysis.
By playing around with the training, I realized that partway through training (80 epochs, or sometimes as few as 40), the slow improvement of the network abruptly cuts off -- the RMSE begins to increase, the RMSE pcutoff reduces to NaN (though in network evaluation it's usually quite high), and the mAP/mAR become 0.00. This persists for the rest of the training (however many epochs were maximum) instead of throwing an error and ending.
Steps To Reproduce
- Create a multi-animal DLC project on 3.0 with 8 body parts per (2) animal(s) and progress past labelling to creating a training dataset and training the network.
- Training, Evaluation and Analysis configuration
- TrainingFraction: - 0.95
- iteration: 0
- default_net_type: resnet_50
- default_augmenter: albumentations
- default_track_method: ellipse
- snapshotindex: -1
- detector_snapshotindex: -1
- batch_size: 8
- 950 epochs, saved every 50 epochs
- Observe error (40+ epochs into training)
LATER:
4. Evaluate Network errors below (I don't know if this is related to the training issue but these are problems I noticed downstream that I haven't encountered with previous multianimal DLC analyses, and I'd appreciate any insight)
Relevant log output
Original (950 epochs) output at end of training:
Epoch 950/950 (lr=1e-05), train loss 0.00642, valid loss 0.66643
Model performance:
metrics/test.rmse: 78.88
metrics/test.rmse_pcutoff: nan
metrics/test.mAP: 0.00
metrics/test.mAR: 0.00
Original training (950 epochs) evaluation:
INFO:console:Evaluation results for DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_760-results.csv (pcutoff: 0.6):
INFO:console:train rmse 30.23
train rmse_pcutoff 43.44
train mAP 0.03
train mAR 0.01
train id_head_Ear_left_accuracy 0.49
train id_head_Ear_right_accuracy 0.49
train id_head_Nose_accuracy 0.50
train id_head_Center_accuracy 0.48
train id_head_Lateral_left_accuracy 0.48
train id_head_Lateral_right_accuracy 0.48
train id_head_Tail_base_accuracy 0.49
train id_head_Tail_end_accuracy 0.50
test rmse 85.63
test rmse_pcutoff 61.84
test mAP 0.00
test mAR 0.00
test id_head_Ear_left_accuracy 0.51
test id_head_Ear_right_accuracy 0.52
test id_head_Nose_accuracy 0.51
test id_head_Center_accuracy 0.49
test id_head_Lateral_left_accuracy 0.48
test id_head_Lateral_right_accuracy 0.48
test id_head_Tail_base_accuracy 0.52
test id_head_Tail_end_accuracy 0.49
Evaluate Network error #1:
:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\deeplabcut\pose_estimation_pytorch\data\postprocessor.py:489: RuntimeWarning: invalid value encountered in cast
heatmap_indices = np.rint(individual_keypoints).astype(int)
Evaluate Network error #2 (Only when I check Plot)
Traceback (most recent call last):
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\deeplabcut\gui\tabs\evaluate_network.py", line 235, in evaluate_network
_ = launch_napari(image_dir)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\deeplabcut\gui\widgets.py", line 46, in launch_napari
viewer.open(files, plugin=plugin, stack=stack)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari\components\viewer_model.py", line 1092, in open
self._add_layers_with_plugins(
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari\components\viewer_model.py", line 1292, in _add_layers_with_plugins
layer_data, hookimpl = read_data_with_plugins(
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari\plugins\io.py", line 77, in read_data_with_plugins
res = _npe2.read(paths, plugin, stack=stack)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari\plugins\_npe2.py", line 63, in read
layer_data, reader = io_utils.read_get_reader(
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\npe2\io_utils.py", line 66, in read_get_reader
return _read(
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\npe2\io_utils.py", line 165, in _read
read_func = rdr.exec(
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\npe2\manifest\contributions\_readers.py", line 61, in exec
callable_ = super().exec(args=args, kwargs=kwargs, _registry=_registry)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\npe2\manifest\utils.py", line 61, in exec
return self.get_callable(reg)(*args, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari_deeplabcut\_reader.py", line 79, in get_folder_parser
layers.extend(read_images(images))
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\napari_deeplabcut\_reader.py", line 112, in read_images
return [(imread(path), params, "image")]
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\dask_image\imread\__init__.py", line 48, in imread
with pims.open(sfname) as imgs:
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\pims\api.py", line 161, in open
return ImageSequence(sequence, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\pims\image_sequence.py", line 68, in __init__
tmp = self.imread(self._filepaths[0], **self.kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\pims\image_sequence.py", line 85, in imread
return imread(filename, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\skimage\_shared\utils.py", line 328, in fixed_func
return func(*args, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\skimage\io\_io.py", line 82, in imread
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\skimage\_shared\utils.py", line 538, in wrapped
return func(*args, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\skimage\io\manage_plugins.py", line 254, in call_plugin
return func(*args, **kwargs)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 11, in imread
out = np.asarray(imageio_imread(*args, **kwargs))
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\imageio\v3.py", line 53, in imread
with imopen(uri, "r", **plugin_kwargs) as img_file:
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\imageio\core\imopen.py", line 113, in imopen
request = Request(uri, io_mode, format_hint=format_hint, extension=extension)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\imageio\core\request.py", line 249, in __init__
self._parse_uri(uri)
File "C:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\imageio\core\request.py", line 409, in _parse_uri
raise FileNotFoundError("No such file: '%s'" % fn)
FileNotFoundError: No such file: 'C:\Users\itilton\Desktop\HW_ResidentIntruderDLC_1-haoyu-2025-08-07\evaluation-results-pytorch\iteration-0\HW_ResidentIntruderDLC_1Aug7-trainset95shuffle1\LabeledImages_DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_760\Test-237_d1_pursuit-img086.png'Anything else?
I noticed that a similar issue was brought up in #2697 , but on my side training starts strong and improves until it suddenly fails (instead of beginning with RMSE pcutoff NaN and mAP/AR=0), and I also have very high RMSE. Not sure if these are related or actually different.
I also found that the labelling on the images in the evaluation-results-pytorch folder doesn't resemble the labelling earlier on -- there's a variety of colors for different body parts. I've attached 1) when one clicks on 'check labels' under label frames and 2) an image under the evaluation results.
Thank you for any help or insight with this issue!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
[-]Sudden training failure (High RMSE, NaN RMSE pcutoff, mAP/mAr=0) partway through training network[/-][+]Sudden training failure (High RMSE, NaN RMSE pcutoff, mAP/mAR=0) partway through training network[/+]tlancaster6 commentedon Sep 10, 2025
have you tried decreasing the initial learning rate? I'm dealing with a similar issue right now, and while reducing lr didn't solve my problem entirely (the losses still explode eventually) it did delay the issue and gave the model enough time to reach acceptable accuracy. you can modify it in the pytorch_config.yaml file by reducing the "runner:optimizer:params:lr" value
pvarsharavi commentedon Sep 10, 2025
Hi! Thank you so much for the insight -- I went ahead and halved the initial learning rate to 0.00025 and hit this error, which I've never faced in training the network.
tlancaster6 commentedon Sep 10, 2025
Not something I've seen before either, but doesn't seem to me like something that would results from modifying the LR. Does the error go away if you chance the LR back to the default?
pvarsharavi commentedon Sep 10, 2025
Nope! I pulled up another project, and that progressed to training without the error, it's just this project (regardless of LR.)
maximpavliv commentedon Sep 19, 2025
Hi @pvarsharavi and @tlancaster6,
I agree with @tlancaster6’s suggestion of lowering the initial learning rate – that would also be my first step to try.
@tlancaster6, did you also adapt the scheduled learning rates in the config (in the pytorch_config.yaml, under
runner:scheduler:params:lr_list)? Sometimes it can help to tweak those values or adjust the milestones if the loss starts exploding later in training.@pvarsharavi, since my suggestion regarding the
KeyError: 'data'in #3095, were you able to re-run the training with a lower initial learning rate (and possibly a modified scheduler as mentioned above)?If the issue persists, could you upload your train.txt and pytorch_config.yaml files so we can take a closer look at the configuration? Those files might give more insight into what’s happening mid-training.
The different colors in labeling are because one image has been colored by individual (this can show if the bodyparts are assigned to the correct individuals, but doesn't distinguish the bodyparts for one individual), the other image has been colored by bodypart (all noses have the same color, all left_ears have the same color, etc .. this is practical to check if the bodyparts are labeled correctly, but doesn't show which individual they belong to). You can change the color mode using the
visualizeindividualsargument ofdeeplabcut.check_labels(), or theplottingargument ofdeeplabcut.evaluate_network().Thanks for sharing the details so far—it’s really helpful for troubleshooting these training issues.
pvarsharavi commentedon Sep 23, 2025
Hi @maximpavliv, thank you for your help!
Your suggestion in #3095 completely cleared up that issue, and I was able to get back to training. Following @tlancaster6's suggestion, after halving the initial learning rate to 0.00025, I was able to complete training. But the resulting RMSE/mAP/mAR weren't ideal -- RMSE plateaued around 9, and mAP/mAR didn't exceed 50.
Since then I've been experimenting with increasing the initial learning rate in increments (currently at 0.00035) to ideally improve training as much as possible without triggering failure. I haven't yet modified the scheduler -- is that something you'd still suggest (in light of the current plateauing RMSE/mAP/mAR) in conjunction with increasing the lr, or would it be best to stick to continue increasing the lr in increments?
And thank you so much for clearing up the labelling colors!
maximpavliv commentedon Sep 24, 2025
Hi @pvarsharavi,
Great to hear you were able to get training running again and thanks for sharing these details.
At this point, I’d strongly recommend looking at your loss curve during training. This is one of the best indicators to guide learning rate adjustments:
Experiment a bit and watch how the loss curve reacts to these changes.
It could be helpful if you could share a plot of your loss curve here.
Also keep in mind that the final RMSE/mAP/mAR are heavily dependent on data quality. If the data is noisy or inconsistent, there’s only so much the model can do.
A few things you might check:
deeplabcut.evaluate_network(..., plotting=True)(docs) to visually compare model predictions on test data with your ground-truth annotations.These steps should help you decide whether further tuning (like scheduler changes) is worthwhile, or if the next gains will come more from improving the dataset itself.
pvarsharavi commentedon Sep 26, 2025
Hi @maximpavliv,
Thank you so much again for all your guidance as I navigate this. I've attached some more details that might be useful after playing around a bit more with the lr and scheduler.
How do training metrics compare to test metrics? They seem more or less the same, but not ideal -- mAP/AR rarely exceed 50, and RMSE remains around 9-10.
Use deeplabcut.evaluate_network(..., plotting=True): I've been meaning to post a ticket about this, but though the csvs/evaluation data is produced at this step, if I check plotting, I run into this error. This has persisted for a while outside of the training (only on this project, but on DLC 2.3 as well as 3.0) so I don't think it's related to the training issues, but it does interfere a bit here.
Error 1 always occurs in the middle of evaluation:
:\Users\itilton\AppData\Local\anaconda3\envs\DEEPLABCUT\lib\site-packages\deeplabcut\pose_estimation_pytorch\data\postprocessor.py:489: RuntimeWarning: invalid value encountered in castError 2 only if I check plotting:
FileNotFoundError: No such file: 'C:\Users\itilton\Desktop\HW_ResidentIntruderDLC_1-haoyu-2025-08-07\evaluation-results-pytorch\iteration-0\HW_ResidentIntruderDLC_1Aug7-trainset95shuffle1\LabeledImages_DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_020\Test-237_d1_pursuit-img086.png'Label Refinement: As the training metrics seemed similar to the test metrics, I haven't gone ahead yet with this step, but if I've overlooked anything and that would address the training issues, please let me know!
As I put together this reply, I realized I don't have evaluation csvs from all of the lrs that I tried out (0.00025-0.00042 in 0.000025 increments), which leads to a fairly limited insight into what's going on. I'm working on rerunning this and getting those csvs for a more in-depth look, but in the mean time, I've attached recent training results for lr = 0.00033 and 0.00042 respectively, with a modified scheduler for the second.
I'm much less experienced with the scheduler conceptually, and though I looked into the docs before altering it (choosing 50 (earlier than 90) for the first milestone and 250 for the second as I was training for 400 epochs, while keeping the lowered lrs of 0.0001 and 1e-05 constant), please let me know if I misunderstood and exacerbated the training issues!
Also, though I've looked into how to plot loss curves, I'm still a beginner delving into machine learning so I'm not entirely sure where the pertinent csvs are located in the Deep Lab Cut project folder. If I could have a bit of guidance on where/how to access the losses, I could work on plotting and sharing that as well!
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_020_lr00033-results.csv
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_030_lr00042-results.csv
pvarsharavi commentedon Sep 26, 2025
Hi @maximpavliv, thank you so much for your help again! Here are the additional training result csvs from lr = 0.00035, 0.00037, 0.0004, and 0.00041. These (unlike the 0.00033 and 0.00042 csvs) were also run for 100 epochs instead of 300 because I noticed training was strongest kept in this region. Nevertheless, even then it doesn't tend to exceed mAP/AR = 50-55 and ~8-9 for RMSE.
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_020-results_lr0.00037.csv
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_060_lr00035-results.csv
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_060-results_lr0.0004.csv
DLC_Resnet50_HW_ResidentIntruderDLC_1Aug7shuffle1_snapshot_100-results_lr00041.csv
pvarsharavi commentedon Sep 30, 2025
Hi @maximpavliv, let me know if I can provide any more information / the necessary files to help navigate this issue.
Once again, thank you so much for your guidance so far!
deruyter92 commentedon Dec 5, 2025
Hi @pvarsharavi, I don't know if you are still encountering problems with training. As mentioned by @maximpavliv, the performance is also highly dependent on your data quality. Besides looking at your loss curves, that is the most important step that can help you further optimize your models performance. Let me know if there are any persistent issues. If you have no further questions, we are going ahead and close this issue.
deruyter92 commentedon Jul 28, 2026
Hi @pvarsharavi, I am reopening this issue as you mentioned (in #3352) you are still encountering training issues (NaN values in the training loss or stagnant loss curves with low LR).
I would like to investigate this issue, to see if this is a bug or just non-optimal hyperparameter tuning.
Would you be willing to maybe share your project files with us? It might be easier to investigate by reproducing the issue ourselves.
E.g. a google drive link or something similar would be helpful.
Thanks in advance!
pvarsharavi commentedon Jul 29, 2026
Hi @deruyter92 ,
Here's the link! It's missing a few files that won't upload for some reason (retried 3x) -- I've added a screenshot of the error message.
deruyter92 commentedon Aug 3, 2026
Hi @pvarsharavi,
Just wanted to let you know that I'm investigating the issue. Quick question: from a first observation it seems that you are training a model with identity head on mostly data with two animals, but you define three individuals:
"mouse1","mouse2"and"". Is that intended? This seems like a potential mistake to me, as more than 99 percent (but not all) of your data contains just labels for two animals.Especially when you are training with identity head (i.e. you teach the model to recognize individuals), including a ghost individual with very sparse data (just 3-4 labels) might be destabilizing on your training performance.
pvarsharavi commentedon Aug 3, 2026
Hi @deruyter92,
Great point -- I hadn't noticed that at all, it must've been a mistake on our part. I just went through and deleted that from the config.yaml. I'll try and retrain in the meantime to see if that helps clear things up.
deruyter92 commentedon Aug 4, 2026
@pvarsharavi,
I took the liberty of trying it myself as well. I cannot find anything inherently wrong with the project, nor any bugs in DeepLabCut related to your training. Here is an example of the model predictions on one of the train examples indicating that it learns well:
Some tips
rtmpose_smodel, which might show less overfitting), train settings (freeze_bn_stats: true) to optimize the performance, but usually the biggest gain is in the dataset itself. This you would have to compare for yourself. Using the default values should give adequate performance for most users.Unless you have further questions, I will close this issue, since there seems to be nothing wrong with the code.
Good luck with your training!
pvarsharavi commentedon Aug 12, 2026
Hi @deruyter92,
Though I noticed successful training on this step, the analysis process produced pose estimation videos with body-part configurations that don't match up consistently with the animals in question. I wanted to check in on whether this was a data issue that could be resolved by the suggestions you mention above, or an analysis / post-analysis / downstream issue that could be more easily resolved before I use the pose estimation data for the next step (which, here, would be the SimBA program).
I've attached a folder with one set of the .h5s and pose estimation videos so you can see what I mean, and can provide the rest if you think that could help. I faced a similar issue a very long time ago on a project with limited frame labelling, but I don't think this is an issue of limited labelling as we labelled hundreds of frames in DLC for this project.
pvarsharavi commentedon Aug 29, 2026
Hi @deruyter92 ,
Just following up on this!
pvarsharavi commentedon Sep 1, 2026
Hi @deruyter92 ,
Just following up on this -- let me know if I can provide any further information!
deruyter92 commentedon Sep 8, 2026
Hi @pvarsharavi,
Sorry for the late response. We are currently busy preparing for a next release.
Since your current problem is related to the analysis and not the training, I think it is separate from the one this issue started with.
What I see on the provided videos is bad predictions, but it is difficult for me to reason where these originate. Looking into it, I found a bug in the ellipse tracker that can put one animal's body parts into the other animal's track. I have just opened a new issue for it (see #3493), but I really cannot tell for sure if it is related to your problem.
Two things would help confirm it. Thanks for trying this out. From my perspective it is difficult to pinpoint whether the model is still struggling with your data or if this concerns a bug in our code.
For anything unrelated to this, a separate issue with a concrete description and steps to reproduce is the fastest route. The image.sc forum is also a good place if you would like input from other users.