Skip to content

Error Plotting/Making Videos on MPS - all predictions 0 #2853

Closed

Description

@ottersum

Is there an existing issue for this?

  • I have searched the existing issues

Bug description

Hello. First of all, thank you so much for your help. I'm a DLC beginner, so I apologize if this is not a bug but a issue with my labelling.

I am trying to train my model with videos of birds. I have 244 images and 13 for testing. Because the bird keeps moving, some points disappear which is why I've tried to label with a total of 5 labels. (except for a few seconds, at least one label is visible) This might be a source of error but I've seen people say that labels will automatically disappear when the parts aren't
visible.

I trained my model for 200 epochs when training loss was 0.0000 and validation loss was 0.0002. But when I try to analyze/make labelled videos, the video does not show ANY labels and skeletons. The trajectory plot somehow shows that except for some, most labels have gone to the top left corner (Though the Plot likelihood is high.)

The csv file shows that some tracking is happening. The spreadsheet graph below is what I get when I graph the y-coordinates show in the csv file. Still, some points remain near the axis.

How can I make sure that my video is tracking accurately?

Image

Image

Image

Operating System

MacOS Sonoma 14.3

DeepLabCut version

dlc version 3.0.0rc6
(Terminal said "zsh: command not found: import" when using import deeplabcut. 3.0.0rc6 is what terminal says when GUI is opening)

DeepLabCut mode

single animal

Device type

cpu (mac)

Steps To Reproduce

I am using deeplabcut for pytorch with a gui. My yaml file has 5 body parts and my label was done according to this.

Relevant log output

#final model performance

Epoch 200/200 (lr=1e-06), train loss 0.00000, valid loss 0.00002
Model performance:
  metrics/test.rmse:                    261.97
  metrics/test.rmse_pcutoff:            351.65
  metrics/test.mAP:                       7.74
  metrics/test.mAR:                      12.31
  metrics/test.rmse_detections:         268.90
  metrics/test.rmse_detections_pcutoff: 364.06

Anything else?

No response

Code of Conduct

Activity

  1. n-poulsen commented on Jan 29, 2025

    @n-poulsen
    Contributor

    Hi @ottersum! From the metrics, your model performance looks quite bad (RMSE is pixel error), but the loss indicates the model is well trained.

    I spotted a really weird issue with the MPS device and PyTorch on OSX two days ago, which was fixed in #2849. Could you try:

    • Editing the pytorch_config.yaml file for your model so that you have "device: cpu", and then run evaluate_network again? The metrics should be much better
    • Running pip install --upgrade "git+https://github.com/DeepLabCut/DeepLabCut.git@pytorch_dlc" in your conda environment to have the latest version of the code and evaluate again?
  2. ottersum commented on Jan 29, 2025

    @ottersum
    Author

    @n-poulsen Thank you for your suggestions. I tried applying them below.

    1. I tried adding the device:cpu to my yaml file and the evaulation itself was similar

    INFO:console:train rmse 246.27
    train rmse_pcutoff 383.50
    train mAP 12.10
    train mAR 17.59
    test rmse 269.04
    test rmse_pcutoff 364.52
    test mAP 8.84
    test mAR 11.54

    1. I tried the pip install --upgrade "git+https://github.com/DeepLabCut/DeepLabCut.git@pytorch_dlc" but it said something like the url was invalid so I did pip install --upgrade deeplabcut . Terminal said a bunch of Requirement already satisfied. And when I did the evaulation again, it was the same as above.

    Below are the plot-poses for another video when I tried analyzing it once I did steps 1 and 2. This time all 4 plots were empty and I couldn't see the labels in the video. Still, the csv file (image below) does show some numbers.

    Image Image

    [EDIT] I tried to plot 2 of the tracked x and y values on through spreadsheet. These points seem okay (except for some that are clustered around the origin), but this is not shown on any plots/videos.

    Image

    Since I didn't re-train the model (I just re-evaluated it), I will update again after my training is done (it seems to take a while). Also, you mentioned that my rmse was bad but the training loss/valid loss was good. Is there a reason why this might be?

    Thank you for your help!!

  3. n-poulsen commented on Jan 29, 2025

    @n-poulsen
    Contributor

    @ottersum I believe the loss is very low but the RMSE is high because of the bug I resolved in #2849 (for short - there's a bug in PyTorch where when copying data from an 'MPS' tensor to a 'CPU' tensor only part of the data is copied - which would explain why some of your keypoints are always predicted at 0). You shouldn't need to re-train your model if this was the bug, as the issue was only there for evaluation.

    Could you let me know the full error that's printed when running

    pip install --upgrade "git+https://github.com/DeepLabCut/DeepLabCut.git@pytorch_dlc"

    in your conda environment? I just tried this on my end and didn't get any issues.

    As two next steps, could you please:

    • Run check_labels (in the GUI, it's in the Label frames tab) and check that there are no errors in your annotations (here are the docs for this function)? Really check that the "left"`"right"` labels are correct as that's a common source of error and can really lead to the model being confused.
    • Run evaluate_network with "Plot predictions" selected - and look at what your model predictions look like compared to your ground truth data (documentation for this is here)
  4. ottersum commented on Jan 29, 2025

    @ottersum
    Author

    Thank you for your reply!

    I actually tried the pip install --upgrade "git+https://github.com/DeepLabCut/DeepLabCut.git@pytorch_dlc" again but this time it installed something and worked. (I apologize, but I already deleted the terminal window with the error so I couldn't copy it here.)

    When I checked the labels, I found a total of 6 label order errors. Thank you for pointing this out. I have fixed all labeling for the videos that contained the errors. I didn't train my network according to the fixed labels yet. Please let me know if I should re-train my model and evaluate the new network.

    Despite running the pip upgrade, I've noticed that the problem persisted.

    When I tried evaluating the network, somehow it didn't work now. The progress bars were full as shown below but it was taking forever to load and didn't give me any data in the end. Is this possibly because I fixed the labels and now I'm testing for a old model with a new set?
    100%|█████████████████████████████████████████| 244/244 [09:29<00:00, 2.34s/it]
    100%|███████████████████████████████████████████| 13/13 [00:06<00:00, 2.06it/s]

    As for video analyzing, I've attached a copy of the plot pose that was created from the original model with your pip update code. The video made from 'create videos' still does not have any labels as well.

    Image

    Thank you so much for your help.

  5. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    Thanks @ottersum - now I would start by re-training the network with the fixed labels. To make sure evaluation happens smoothly, you can delete the current evaluation results.

    Let me know if your issue is fixed after this!

  6. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen
    Thank you for your response.
    I've started to re-train my model with the correctly labeled images but noticed after the first 10 epoches that the rmse was still very high.

    Image

    Is this normal for the first 10 epochs or is there still an issue with my DLC or training?

  7. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    The loss is very low compared to the metrics that are being output (with a loss so low, you would expect the model to be almost perfect) - and if the loss is too small, then the model might won't be able to learn anything.

    Would you be willing to share a few of the images you labeled (the ones output by "check labels") so I can take a look and see if I spot anything wrong?

  8. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen
    These are some images that I see when I see check labels. I've also attached a picture I took from the DLC folder of 'labeled-data'. I've labeled a total of 5 parts (left eye, left nostril, between the beak, right nostril and the right eye.) As you can see, not are labels are visible in every frame (I believe most frames have 4 with some even having none when the bird turns around).

    Referring to what you said about the loss being low, do you know why this would this be? When I trained for 200 epochs, the training loss was actually 0.0000 at the end. Do you think this might be the problem?

    Because these videos aren't actually not mine, I am a bit hesitant about leaving it up. Would you mind if I delete them once you respond?

    Thank you so much for your help.

  9. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    @ottersum no problem deleting the images - your data looks well labeled. How large are the images (their resolution in pixels)?

    Referring to what you said about the loss being low, do you know why this would this be? When I trained for 200 epochs, the training loss was actually 0.0000 at the end. Do you think this might be the problem?

    Yes I believe that's a symptom for the issue - could you share your project's config.yaml and thepytorch_config.yaml for the model you trained?

    There's no issues with some keypoints not being visible in images, the model learns not to output those keypoints.

  10. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen Thank you. My images are the pixel of my images are 832 × 724 (from dimensions once I clicked 'get info' on the images). As for the yaml files, I've copied them below.

    (Edit): While I was copying this, I noticed that I added youre device:cpu suggestion to the project yaml instead of the pytorch yaml file. I've added it now. I apologize for the oversight.

    Project yaml

    # Default DeepLabCut engine to use for shuffle creation (either pytorch or tensorflow)
    engine: pytorch
    
    
    # Annotation data set configuration (and individual video cropping parameters)
    video_sets:
      /Users/student/Desktop/hoby for p/Videos/video_0297.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0056.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0125.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0143.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_1139.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0943.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0158.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0922.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0288.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_1141.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_1154.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_1593.avi:
        crop: 0, 832, 0, 724
      /Users/student/Desktop/hoby for p/Videos/video_0926.avi:
        crop: 0, 832, 0, 724
    bodyparts:
    - lefteye
    - righteye
    - beakbtw
    - leftnostril
    - rightnostril
    
    
    # Fraction of video to start/stop when extracting frames for labeling/refinement
    
    
    # Fraction of video to start/stop when extracting frames for labeling/refinement
    start: 0
    stop: 1
    numframes2pick: 20
    
    
    # Plotting configuration
    skeleton:
    - - lefteye
      - leftnostril
    - - leftnostril
      - beakbtw
    - - beakbtw
      - rightnostril
    - - rightnostril
      - righteye
    - - rightnostril
      - leftnostril
    skeleton_color: black
    pcutoff: 0.6
    dotsize: 12
    alphavalue: 0.7
    colormap: rainbow
    
    
    # Training,Evaluation and Analysis configuration
    TrainingFraction:
    - 0.95
    iteration: 0
    default_net_type: resnet_50
    default_augmenter: default
    snapshotindex: -1
    detector_snapshotindex: -1
    batch_size: 8
    detector_batch_size: 1
    
    
    # Cropping Parameters (for analysis and outlier frame detection)
    cropping: false
    #if cropping is true for analysis, then set the values here:
    x1: 0
    x2: 640
    y1: 277
    y2: 624
    
    
    # Refinement configuration (parameters from annotation dataset configuration also relevant in this stage)
    corner2move2:
    - 50
    - 50
    move2corner: true
    
    device: cpu
    
    # Conversion tables to fine-tune SuperAnimal weights
    SuperAnimalConversionTables:
    

    pytorch yaml

    data:
      colormode: RGB
      inference:
        normalize_images: true
      train:
        affine:
          p: 0.5
          rotation: 30
          scaling:
          - 1.0
          - 1.0
          translation: 0
        collate:
          type: ResizeFromDataSizeCollate
          min_scale: 0.4
          max_scale: 1.0
          min_short_side: 128
          max_short_side: 1152
          multiple_of: 32
          to_square: false
        covering: false
        gaussian_noise: 12.75
        hist_eq: false
        motion_blur: false
        normalize_images: true
    device: auto
    metadata:
      project_path: x
      pose_config_path: x
      bodyparts:
      - lefteye
      - righteye
      - beakbtw
      - leftnostril
      - rightnostril
      unique_bodyparts: []
      individuals:
      - animal
      with_identity:
    method: bu
    model:
      backbone:
        type: ResNet
        model_name: resnet50_gn
        output_stride: 16
        freeze_bn_stats: true
        freeze_bn_weights: false
      backbone_output_channels: 2048
      heads:
        bodypart:
          type: HeatmapHead
          weight_init: normal
          predictor:
            type: HeatmapPredictor
            apply_sigmoid: false
            clip_scores: true
            location_refinement: true
            locref_std: 7.2801
          target_generator:
            type: HeatmapGaussianGenerator
            num_heatmaps: 5
            pos_dist_thresh: 17
            heatmap_mode: KEYPOINT
            gradient_masking: false
            generate_locref: true
            locref_std: 7.2801
          criterion:
            heatmap:
              type: WeightedMSECriterion
              weight: 1.0
            locref:
              type: WeightedHuberCriterion
              weight: 0.05
          heatmap_config:
            channels:
            - 2048
            - 5
            kernel_size:
            - 3
            strides:
            - 2
          locref_config:
            channels:
            - 2048
            - 10
            kernel_size:
            - 3
            strides:
            - 2
    net_type: resnet_50
    runner:
      type: PoseTrainingRunner
      gpus:
      key_metric: test.mAP
      key_metric_asc: true
      eval_interval: 10
      optimizer:
        type: AdamW
        params:
          lr: 0.0001
      scheduler:
        type: LRListScheduler
        params:
          lr_list:
          - - 1e-05
          - - 1e-06
          milestones:
          - 160
          - 190
      snapshots:
        max_snapshots: 5
        save_epochs: 50
        save_optimizer_state: false
    train_settings:
      batch_size: 1
      dataloader_workers: 0
      dataloader_pin_memory: false
      display_iters: 1000
      epochs: 200
      seed: 42
    device: cpu
    

    [edit]: Just in case it helps, this is the latest evaluation for the model I am trying to train with newly labeled images.

    Epoch 80/200 (lr=0.0001), train loss 0.00002, valid loss 0.00004
    Model performance:
      metrics/test.rmse:                    262.06
      metrics/test.rmse_pcutoff:            381.20
      metrics/test.mAP:                       7.71
      metrics/test.mAR:                      12.31
      metrics/test.rmse_detections:         269.08
      metrics/test.rmse_detections_pcutoff: 392.34
    

    Thank you so much. Please let me know if you need any more information!

  11. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    @ottersum no worries! the device key is actually already present a bit higher up in the pytorch_config.yaml for your model (see device: auto) - could you edit it there as well so you have:

    data:
      colormode: RGB
      inference:
        normalize_images: true
      train:
        affine:
          p: 0.5
          ...
    device: cpu
    metadata:
      project_path: /Users/student/Desktop/h/Birds-LK-2025-01-28
      ...

    And try running "evaluate network" again (delete the content of the evaluation-results-pytorch folder first, so we're sure the results are fresh)?

  12. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen Thank you so much for the quick reply!
    I've changed device:auto into device:cpu in the pytorch yaml file. I'm actually training the new model right now so I can't evaluate it just yet. I edited my previous message to include an update with the training which I've copied below.

    Epoch 80/200 (lr=0.0001), train loss 0.00002, valid loss 0.00004
    Model performance:
      metrics/test.rmse:                    262.06
      metrics/test.rmse_pcutoff:            381.20
      metrics/test.mAP:                       7.71
      metrics/test.mAR:                      12.31
      metrics/test.rmse_detections:         269.08
      metrics/test.rmse_detections_pcutoff: 392.34
    

    I've deleted the old evaluation results file in my DLC folder during training too. Would it be okay if I update you with 'evaluate network' results once my training is complete?

  13. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    @ottersum that would be good - could you also run the "extract_save_all_maps" function? You need to do this through code though (it isn't available in the GUI yet - you can open a shell by calling ipython in your terminal):

    (DEEPLABCUT) > ipython
    In [1]: import deeplabcut
    Loading DLC 3.0.0rc6...
    In [2]: config = "/Users/student/Desktop/h/Birds-LK-2025-01-28/config.yaml"
    In [3]: deeplabcut.extract_save_all_maps(config, shuffle=1, Indices=[0, 1, 2])
    

    Then if you can share the maps that are produced in the evaluate_network folder?

  14. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    @ottersum ah sorry - this isn't a big issue; just need to run evaluate_network first (and no worries about deleting messages):

    (DEEPLABCUT) > ipython
    In [1]: import deeplabcut
    Loading DLC 3.0.0rc6...
    In [2]: config = "/Users/student/Desktop/h/Birds-LK-2025-01-28/config.yaml"
    In [3]: deeplabcut.evaluate_network(config, Shuffles=[1], device="cpu")
    In [4]: deeplabcut.extract_save_all_maps(config, shuffle=1, Indices=[0, 1, 2])
    
  15. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen Thank you for your understanding!
    The new set with the evaluate network seemed to work perfectly. Once I completed deeplabcut.evaluate_network(config, Shuffles=[1], device="cpu") I got a new set of evaluations that seem to be different from what I have been getting.

    Evaluation results for DLC_Resnet50_(name)Jan28shuffle1_snapshot_090-results.csv (pcutoff: 0.6):
    train rmse             2.53
    train rmse_pcutoff     2.49
    train mAP             95.09
    train mAR             96.47
    test rmse              3.92
    test rmse_pcutoff      3.89
    test mAP              87.66
    test mAR              89.23
    Name: (0.95, 1, 90, -1, 0.6), dtype: float64
    
  16. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    Awesome your model results look great!! With the results you have I think you can easily start analyzing videos; performance looks very good.

    I'll close the issue as I think your problem is resolved, but don't hesitate to re-open it if you run into other issues!

  17. ottersum commented on Jan 30, 2025

    @ottersum
    Author

    @n-poulsen I hope you don't mind me asking 2 additional questions...

    1. If I were to make another project, are there any steps I should take to prevent this from happening again? (should I change the yaml device:cpu in following projects?)
    2. This is more of a general question. If I trained my model with a certain set of videos, can i apply the model to track the same video but as a different file? Just for context, will my model accurately track if I were to analyze smaller trimmed videos of the videos I used for training?

    Thank you so much for your help!

  18. changed the title [-]Error Plotting / Making Videos[/-] [+]Error Plotting/Making Videos on MPS - all predictions 0[/+] on Jan 30, 2025
  19. n-poulsen commented on Jan 30, 2025

    @n-poulsen
    Contributor

    Of course!

    1. I believe the issue might still be that the version didn't update correctly. So I would try re-installing again, but the way to do so might be to run:
    pip uninstall deeplabcut
    pip install "git+https://github.com/DeepLabCut/DeepLabCut.git@pytorch_dlc"
    

    You can then try analyzing videos with your trained model and device: auto again, and the results should be basically the same as with device: cpu. If that's not the case, you can re-open this issue and I can help!

    1. Depending on how different the new videos are, performance might be a bit worse; but the easiest way to determine that is to analyze the new videos with your model and see if performance is sufficient. If the videos are just smaller trimmed versions of the ones used for training performance should basically be as good as the performance on the original video.
  20. ottersum commented on Jan 31, 2025

    @ottersum
    Author

    Thank you for your reply!
    I will try to update DLC later when I need it for another project. I've afraid it might stop working if I update it now...
    As for the new model that has finished training today, I've attached a picture of the new plots that work perfectly. The labelled videos look good as well.

    Image

    Image

    Thank you so much for all your help!!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions