Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YOLO Segment sigmoid() fix #13939

Merged
merged 15 commits into from
Jun 25, 2024
Merged

YOLO Segment sigmoid() fix #13939

merged 15 commits into from
Jun 25, 2024

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Jun 24, 2024

…chieve better segmentation edges. (#13912)

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

This PR simplifies mask processing logic and enhances testing in the Ultralytics repository.

📊 Key Changes

  • Updated CI workflow to install pytest-cov for test coverage reporting.
  • Modified process_mask_* functions in ultralytics/utils/ops.py to remove unnecessary sigmoid operations and adjusted the mask threshold condition.

🎯 Purpose & Impact

  • Enhanced Testing: 👍 Adding pytest-cov helps in measuring test coverage, leading to higher code quality and reliability.
  • Optimization: 🚀 Simplifying mask processing by removing redundant operations slightly improves performance and reduces computational overhead.
  • Accuracy Adjustment: 🎯 Adjusting the mask threshold from 0.5 to 0.0 could impact mask generation results, potentially increasing model sensitivity.

zxDeepDiver and others added 2 commits June 24, 2024 17:37
…chieve better segmentation edges. (#13912)

Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.25%. Comparing base (3bb0c5a) to head (da3aa13).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13939   +/-   ##
=======================================
  Coverage   70.25%   70.25%           
=======================================
  Files         124      124           
  Lines       15891    15891           
=======================================
  Hits        11164    11164           
  Misses       4727     4727           
Flag Coverage Δ
Benchmarks 35.81% <33.33%> (ø)
GPU 36.90% <0.00%> (ø)
Tests 66.48% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
@glenn-jocher glenn-jocher changed the title Segment Sigmoid() fix ultralytics 8.2.42 Segment Sigmoid() fix Jun 24, 2024
@glenn-jocher glenn-jocher changed the title ultralytics 8.2.42 Segment Sigmoid() fix ultralytics 8.2.42 YOLO Segment sigmoid() fix Jun 24, 2024
@glenn-jocher
Copy link
Member Author

Main branch results:

root@113944910eee:/usr/src/ultralytics# yolo val model=yolov8n-seg.pt data=coco.yaml device=5 
Ultralytics YOLOv8.2.41 🚀 Python-3.10.14 torch-2.3.1 CUDA:5 (NVIDIA A100-SXM4-80GB, 81051MiB)
YOLOv8n-seg summary (fused): 195 layers, 3404320 parameters, 0 gradients, 12.6 GFLOPs
val: Scanning /usr/src/datasets/coco/labels/val2017.cache... 4952 images, 48 backgrounds, 0 corrupt: 100%|██████████| 5000/5000 [00:00<?, ?it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 313/313 [13:45<00:00,  2.64s/it]
                   all       5000      36335      0.621       0.48      0.518      0.364      0.622      0.457      0.491      0.306
                person       2693      10777      0.742       0.68      0.744      0.515      0.741      0.651       0.71        0.4
               bicycle        149        314      0.629      0.385      0.445      0.245      0.585      0.334       0.36      0.135
                   car        535       1918      0.632      0.516      0.556      0.356      0.638      0.484      0.528      0.296
            motorcycle        159        367      0.702      0.567      0.657      0.406      0.687      0.518      0.576      0.286
              airplane         97        143      0.715      0.769      0.822      0.639      0.739      0.769      0.792      0.492
                   bus        189        283      0.744      0.707      0.751      0.608      0.754      0.692      0.735      0.559
                 train        157        190      0.827      0.782      0.851      0.635      0.815       0.74      0.818      0.599
                 truck        250        414      0.541      0.391      0.451        0.3      0.547      0.365      0.415      0.253
                  boat        121        424      0.545       0.34      0.369      0.197      0.528      0.292      0.332      0.144
         traffic light        191        634       0.58      0.338      0.384      0.198      0.607      0.326      0.383      0.184
          fire hydrant         86        101      0.852      0.723      0.775      0.619      0.861      0.723      0.778      0.561
             stop sign         69         75      0.706      0.627      0.672      0.603      0.717      0.608      0.672      0.573
         parking meter         37         60      0.752        0.5      0.608      0.442      0.772        0.5      0.584      0.407
                 bench        235        411      0.543      0.277      0.305      0.201      0.532      0.253      0.269      0.132
                  bird        125        427      0.588      0.365      0.409      0.271      0.605      0.356      0.397      0.219
                   cat        184        202      0.744      0.822      0.838      0.646      0.759      0.812      0.849      0.626
                   dog        177        218      0.676      0.679      0.716      0.574      0.699      0.671       0.71      0.532
                 horse        128        272      0.715      0.658      0.718      0.537      0.721      0.645      0.689      0.376
                 sheep         65        354      0.559      0.644      0.656      0.447      0.573      0.624      0.629      0.367
                   cow         87        372      0.656      0.616      0.673      0.475      0.655      0.581      0.633       0.38
              elephant         89        252      0.722      0.837      0.813      0.619      0.738      0.845      0.825      0.554
                  bear         49         71      0.793      0.845       0.85      0.679      0.769      0.817      0.831      0.654
                 zebra         85        266      0.774      0.835      0.892      0.668      0.791      0.823      0.871       0.55
               giraffe        101        232      0.848      0.843      0.892      0.695      0.836      0.819      0.858       0.54
              backpack        228        371       0.44       0.17      0.183     0.0939      0.442      0.151      0.168     0.0796
              umbrella        174        407      0.631      0.499      0.544      0.366      0.693      0.516      0.573      0.378
               handbag        292        540        0.5      0.152      0.179     0.0902      0.547      0.143      0.171     0.0815
                   tie        145        252       0.67      0.397      0.441      0.279      0.709      0.397      0.436       0.24
              suitcase        105        299      0.598      0.408      0.473      0.322      0.607      0.381      0.445      0.288
               frisbee         84        115      0.776      0.678      0.761      0.591      0.799      0.678      0.761      0.534
                  skis        120        241      0.552      0.357      0.368      0.188      0.392      0.228      0.201     0.0433
             snowboard         49         69      0.527      0.348      0.368       0.26      0.514      0.319      0.329      0.166
           sports ball        169        260      0.683      0.455      0.479      0.329      0.686      0.438       0.46      0.278
                  kite         91        327      0.583      0.538      0.571      0.378      0.577      0.483      0.524      0.275
          baseball bat         97        145       0.54      0.379      0.398      0.217      0.589      0.385      0.395      0.171
        baseball glove        100        148      0.633      0.493      0.526      0.319      0.651      0.473      0.526      0.303
            skateboard        127        179      0.656      0.665      0.662      0.463      0.622      0.592      0.596      0.273
             surfboard        149        267      0.608      0.502      0.518      0.311      0.604      0.472      0.488      0.242
         tennis racket        167        225      0.715      0.627      0.673      0.392      0.737      0.622      0.673      0.431
                bottle        379       1013      0.603      0.397      0.449      0.294      0.605      0.373      0.426      0.255
            wine glass        110        341        0.7      0.346      0.422      0.275      0.697      0.323      0.379      0.205
                   cup        390        895       0.59      0.426      0.469      0.336      0.591      0.406      0.451      0.308
                  fork        155        215      0.577      0.349      0.372      0.248      0.547      0.302      0.279      0.118
                 knife        181        325      0.474      0.163      0.177      0.104      0.471      0.154      0.144     0.0688
                 spoon        153        253      0.383      0.138      0.158     0.0877      0.403      0.125      0.124     0.0502
                  bowl        314        623       0.61      0.492       0.53      0.399       0.58      0.446      0.471      0.277
                banana        103        370       0.52      0.311      0.341      0.216       0.53      0.286      0.312      0.164
                 apple         76        236      0.399      0.205      0.209      0.148      0.413      0.191      0.199      0.133
              sandwich         98        177      0.563      0.492      0.483      0.358      0.538      0.446      0.418      0.312
                orange         85        285      0.483        0.4      0.377      0.293      0.495      0.386      0.363      0.256
              broccoli         71        312      0.513      0.369      0.376      0.207      0.567      0.378      0.383      0.182
                carrot         81        365      0.433       0.29      0.278      0.176      0.439      0.268      0.265      0.145
               hot dog         51        125      0.581      0.388      0.419      0.285      0.527      0.336      0.342      0.201
                 pizza        153        284      0.683      0.613      0.668        0.5      0.688      0.602      0.638      0.452
                 donut         62        328      0.557      0.476      0.515      0.403      0.575      0.462      0.505      0.372
                  cake        124        310      0.509      0.378      0.429      0.272      0.534      0.371      0.425      0.259
                 chair        580       1771      0.574      0.343      0.398      0.246      0.541        0.3      0.333      0.148
                 couch        195        261      0.588      0.559      0.589      0.444      0.581      0.521      0.529      0.344
          potted plant        172        342       0.52      0.354      0.367      0.211       0.49      0.316       0.31      0.132
                   bed        149        163      0.572      0.558      0.573      0.389      0.541      0.509      0.488       0.29
          dining table        501        695      0.511      0.442      0.418      0.276      0.402      0.324      0.271      0.103
                toilet        149        179      0.674      0.729       0.76      0.623      0.728      0.737      0.774      0.585
                    tv        207        288       0.67      0.646      0.688      0.528      0.683      0.639      0.683      0.491
                laptop        183        231      0.637      0.615      0.667      0.541      0.615      0.574      0.595      0.383
                 mouse         88        106      0.648      0.695      0.703      0.521      0.655      0.679      0.681      0.481
                remote        145        283      0.429      0.219      0.268      0.156      0.488      0.225      0.267      0.133
              keyboard        106        153      0.635      0.608      0.636      0.461      0.635      0.582      0.642      0.441
            cell phone        214        262      0.519      0.363      0.378      0.252      0.536       0.34      0.369       0.23
             microwave         54         55       0.57      0.554      0.611       0.49       0.57       0.53      0.615      0.452
                  oven        115        143      0.627      0.483      0.541      0.355      0.619      0.454      0.479      0.278
               toaster          8          9          1      0.214      0.565       0.38          1       0.21      0.565      0.427
                  sink        187        225      0.588      0.498      0.506      0.335      0.619      0.507      0.513      0.298
          refrigerator        101        126      0.711      0.635      0.677      0.521      0.736      0.627      0.683      0.491
                  book        230       1129      0.459      0.113      0.181     0.0872      0.389     0.0834      0.121     0.0473
                 clock        204        267      0.662      0.615      0.648      0.444      0.678      0.614      0.659      0.426
                  vase        137        274      0.547      0.428      0.444      0.302      0.543      0.401      0.414      0.263
              scissors         28         36      0.521      0.302      0.304      0.229      0.507      0.278      0.303      0.155
            teddy bear         94        190      0.703      0.558      0.623      0.458      0.713      0.553      0.611      0.409
            hair drier          9         11          1          0    0.00414    0.00218          1          0     0.0398     0.0116
            toothbrush         34         57      0.455      0.228      0.188      0.117       0.45      0.211      0.197     0.0831
Speed: 0.1ms preprocess, 1.4ms inference, 0.0ms loss, 0.9ms postprocess per image
Saving /usr/src/ultralytics/runs/segment/val3/predictions.json...

Evaluating pycocotools mAP using /usr/src/ultralytics/runs/segment/val3/predictions.json and /usr/src/datasets/coco/annotations/instances_val2017.json...
loading annotations into memory...
Done (t=0.39s)
creating index...
index created!
Loading and preparing results...
DONE (t=7.10s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=58.32s).
Accumulating evaluation results...
DONE (t=13.35s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.367
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.522
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.398
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.179
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.404
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.521
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.315
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.532
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.586
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.366
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.650
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.767
Running per image evaluation...
Evaluate annotation type *segm*
DONE (t=64.70s).
Accumulating evaluation results...
DONE (t=13.44s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.304
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.491
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.321
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.122
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.334
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.461
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.273
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.437
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.472
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.252
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.532
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.674
Results saved to /usr/src/ultralytics/runs/segment/val3
💡 Learn more at https://docs.ultralytics.com/modes/val

@glenn-jocher
Copy link
Member Author

PR results

root@113944910eee:/usr/src/ultralytics# yolo val model=yolov8n-seg.pt data=coco.yaml device=5
Downloading https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n-seg.pt to 'yolov8n-seg.pt'...
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6.73M/6.73M [00:00<00:00, 230MB/s]
Ultralytics YOLOv8.2.42 🚀 Python-3.10.14 torch-2.3.1 CUDA:5 (NVIDIA A100-SXM4-80GB, 81051MiB)
YOLOv8n-seg summary (fused): 195 layers, 3404320 parameters, 0 gradients, 12.6 GFLOPs
val: Scanning /usr/src/datasets/coco/labels/val2017.cache... 4952 images, 48 backgrounds, 0 corrupt: 100%|██████████| 5000/5000 [00:00<?, ?it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95)     Mask(P          R      mAP50  mAP50-95): 100%|██████████| 313/313 [13:46<00:00,  2.64s/it]
                   all       5000      36335      0.621       0.48      0.518      0.364      0.622      0.456       0.49      0.303
                person       2693      10777      0.742       0.68      0.744      0.515      0.741       0.65      0.709      0.395
               bicycle        149        314      0.629      0.385      0.445      0.245      0.585      0.334       0.36      0.135
                   car        535       1918      0.632      0.516      0.556      0.356      0.638      0.484      0.526      0.291
            motorcycle        159        367      0.702      0.567      0.657      0.406      0.688      0.518      0.575      0.286
              airplane         97        143      0.715      0.769      0.822      0.639      0.739      0.769      0.792       0.48
                   bus        189        283      0.744      0.707      0.751      0.608      0.753      0.691      0.735      0.559
                 train        157        190      0.827      0.782      0.851      0.635      0.814      0.739      0.818      0.599
                 truck        250        414      0.541      0.391      0.451        0.3      0.549      0.365      0.415      0.251
                  boat        121        424      0.545       0.34      0.369      0.197      0.526       0.29      0.326      0.142
         traffic light        191        634       0.58      0.338      0.384      0.198      0.609      0.326      0.381      0.182
          fire hydrant         86        101      0.852      0.723      0.775      0.619      0.862      0.723      0.778      0.551
             stop sign         69         75      0.706      0.627      0.672      0.603      0.717      0.607      0.672      0.575
         parking meter         37         60      0.752        0.5      0.608      0.442      0.773        0.5      0.584      0.406
                 bench        235        411      0.543      0.277      0.305      0.201      0.532      0.253      0.269      0.132
                  bird        125        427      0.588      0.365      0.409      0.271      0.602      0.351      0.394      0.216
                   cat        184        202      0.744      0.822      0.838      0.646      0.764      0.812      0.849      0.626
                   dog        177        218      0.676      0.679      0.716      0.574      0.699       0.67       0.71      0.528
                 horse        128        272      0.715      0.658      0.718      0.537       0.72      0.644      0.689      0.373
                 sheep         65        354      0.559      0.644      0.656      0.447      0.571      0.621      0.627      0.362
                   cow         87        372      0.656      0.616      0.673      0.475      0.655      0.581      0.633      0.373
              elephant         89        252      0.722      0.837      0.813      0.619      0.739      0.845      0.825      0.552
                  bear         49         71      0.793      0.845       0.85      0.679       0.77      0.817      0.831      0.652
                 zebra         85        266      0.774      0.835      0.892      0.668      0.795      0.823      0.871      0.549
               giraffe        101        232      0.848      0.843      0.892      0.695      0.836      0.819      0.858      0.537
              backpack        228        371       0.44       0.17      0.183     0.0939      0.446      0.151      0.167     0.0774
              umbrella        174        407      0.631      0.499      0.544      0.366      0.689      0.513      0.571      0.373
               handbag        292        540        0.5      0.152      0.179     0.0902      0.548      0.142      0.171     0.0795
                   tie        145        252       0.67      0.397      0.441      0.279      0.708      0.393      0.436      0.234
              suitcase        105        299      0.598      0.408      0.473      0.322      0.608      0.381      0.445      0.288
               frisbee         84        115      0.776      0.678      0.761      0.591        0.8      0.678      0.761      0.521
                  skis        120        241      0.552      0.357      0.368      0.188      0.379       0.22      0.192     0.0395
             snowboard         49         69      0.527      0.348      0.368       0.26      0.515      0.319      0.324      0.164
           sports ball        169        260      0.683      0.455      0.479      0.329      0.682      0.435      0.455      0.267
                  kite         91        327      0.583      0.538      0.571      0.378      0.581      0.486      0.523      0.258
          baseball bat         97        145       0.54      0.379      0.398      0.217      0.598       0.39      0.409      0.163
        baseball glove        100        148      0.633      0.493      0.526      0.319      0.652      0.473      0.525      0.298
            skateboard        127        179      0.656      0.665      0.662      0.463      0.622      0.592      0.596      0.271
             surfboard        149        267      0.608      0.502      0.518      0.311      0.591      0.461      0.482      0.238
         tennis racket        167        225      0.715      0.627      0.673      0.392      0.736      0.621      0.673      0.424
                bottle        379       1013      0.603      0.397      0.449      0.294      0.606      0.371      0.426      0.251
            wine glass        110        341        0.7      0.346      0.422      0.275      0.698      0.323      0.376      0.203
                   cup        390        895       0.59      0.426      0.469      0.336      0.592      0.406      0.451      0.305
                  fork        155        215      0.577      0.349      0.372      0.248      0.549      0.302      0.278      0.117
                 knife        181        325      0.474      0.163      0.177      0.104       0.47      0.151      0.142     0.0667
                 spoon        153        253      0.383      0.138      0.158     0.0877      0.397      0.122      0.121     0.0486
                  bowl        314        623       0.61      0.492       0.53      0.399      0.581      0.445      0.471      0.276
                banana        103        370       0.52      0.311      0.341      0.216      0.524      0.282      0.311      0.163
                 apple         76        236      0.399      0.205      0.209      0.148      0.414      0.191      0.199      0.132
              sandwich         98        177      0.563      0.492      0.483      0.358      0.539      0.446      0.418      0.312
                orange         85        285      0.483        0.4      0.377      0.293      0.494      0.382      0.363      0.256
              broccoli         71        312      0.513      0.369      0.376      0.207      0.562      0.374      0.381      0.182
                carrot         81        365      0.433       0.29      0.278      0.176      0.441      0.266      0.264      0.143
               hot dog         51        125      0.581      0.388      0.419      0.285      0.528      0.336      0.342      0.201
                 pizza        153        284      0.683      0.613      0.668        0.5      0.689      0.602      0.638      0.451
                 donut         62        328      0.557      0.476      0.515      0.403      0.574      0.461      0.505       0.37
                  cake        124        310      0.509      0.378      0.429      0.272      0.534      0.368      0.425      0.259
                 chair        580       1771      0.574      0.343      0.398      0.246       0.54      0.299      0.332      0.147
                 couch        195        261      0.588      0.559      0.589      0.444       0.58      0.519      0.529      0.342
          potted plant        172        342       0.52      0.354      0.367      0.211       0.49      0.316       0.31      0.131
                   bed        149        163      0.572      0.558      0.573      0.389      0.541      0.509      0.488       0.29
          dining table        501        695      0.511      0.442      0.418      0.276      0.402      0.324      0.271      0.103
                toilet        149        179      0.674      0.729       0.76      0.623       0.73      0.737      0.774      0.585
                    tv        207        288       0.67      0.646      0.688      0.528      0.684      0.639      0.683       0.49
                laptop        183        231      0.637      0.615      0.667      0.541      0.615      0.571      0.595      0.383
                 mouse         88        106      0.648      0.695      0.703      0.521      0.655      0.679      0.681      0.475
                remote        145        283      0.429      0.219      0.268      0.156      0.487      0.225      0.266       0.13
              keyboard        106        153      0.635      0.608      0.636      0.461      0.636      0.582      0.642       0.44
            cell phone        214        262      0.519      0.363      0.378      0.252      0.537       0.34      0.366      0.229
             microwave         54         55       0.57      0.554      0.611       0.49      0.569      0.529      0.615       0.45
                  oven        115        143      0.627      0.483      0.541      0.355      0.617       0.45      0.479      0.278
               toaster          8          9          1      0.214      0.565       0.38          1      0.209      0.565      0.418
                  sink        187        225      0.588      0.498      0.506      0.335      0.622      0.504      0.513      0.297
          refrigerator        101        126      0.711      0.635      0.677      0.521      0.737      0.627      0.683       0.49
                  book        230       1129      0.459      0.113      0.181     0.0872      0.389     0.0824       0.12     0.0463
                 clock        204        267      0.662      0.615      0.648      0.444      0.678      0.614      0.659      0.422
                  vase        137        274      0.547      0.428      0.444      0.302      0.543      0.401      0.414      0.261
              scissors         28         36      0.521      0.302      0.304      0.229      0.516      0.278      0.303      0.156
            teddy bear         94        190      0.703      0.558      0.623      0.458      0.714      0.553      0.611      0.409
            hair drier          9         11          1          0    0.00414    0.00218          1          0     0.0398     0.0116
            toothbrush         34         57      0.455      0.228      0.188      0.117      0.451      0.211      0.197     0.0819
Speed: 0.1ms preprocess, 1.4ms inference, 0.0ms loss, 0.9ms postprocess per image
Saving /usr/src/ultralytics/runs/segment/val/predictions.json...

Evaluating pycocotools mAP using /usr/src/ultralytics/runs/segment/val/predictions.json and /usr/src/datasets/coco/annotations/instances_val2017.json...
loading annotations into memory...
Done (t=0.40s)
creating index...
index created!
Loading and preparing results...
DONE (t=7.28s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=57.65s).
Accumulating evaluation results...
DONE (t=13.32s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.367
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.522
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.398
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.179
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.404
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.521
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.315
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.532
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.586
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.366
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.650
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.767
Running per image evaluation...
Evaluate annotation type *segm*
DONE (t=64.19s).
Accumulating evaluation results...
DONE (t=13.39s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.304
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.491
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.320
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.121
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.334
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.461
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.273
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.436
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.471
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.251
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.532
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.674
Results saved to /usr/src/ultralytics/runs/segment/val
💡 Learn more at https://docs.ultralytics.com/modes/val

@glenn-jocher glenn-jocher changed the title ultralytics 8.2.42 YOLO Segment sigmoid() fix YOLO Segment sigmoid() fix Jun 24, 2024
@glenn-jocher
Copy link
Member Author

glenn-jocher commented Jun 24, 2024

@Laughing-q this fix PR seems to make a lot of sense, and the edges are much smoother (see #13912), but segment mAP drops very slightly after implementing it. What do you think?

@Laughing-q
Copy link
Member

@glenn-jocher I also tested yolov8s-seg and yolov8m-seg, both of them shown slightly mAP drop as well.
yolov8m-seg:

 # main
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.405
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.633
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.432
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.216
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.456
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.582
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.327
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.521
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.556
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.621
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.741

 # segment-fix
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.404
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.634
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.431
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.213
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.456
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.581
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.326
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.520
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.555
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.347
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.620
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.740

yolov8s-seg:

 # main
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.366
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.580
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.387
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.168
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.410
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.537
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.306
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.488
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.521
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.301
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.585
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.715
 # segment-fix
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.365
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.580
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.385
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.168
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.409
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.537
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.306
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.487
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.520
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.300
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.583
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.714

But the update does show better visualization, meanwhile eliminating sigmoid operator should be slightly faster in post-processing. How about we remove it and leave a comment says using sigmoid might get better mAP and see #13939 ?

@Laughing-q
Copy link
Member

Laughing-q commented Jun 25, 2024

@glenn-jocher Here are some visualized samples on main branch and this branch, and it looks like on the latter in some level it's fixing the "cut" issue we are having when retina_mask=False. Let's leave a comment and merge this then. :)
qSmx5Zouii
pIkZiW9zPb

BTW I think we are having too many process_mask functions even though each one of them stands for different case. I'll take a look at this part when I have time and try to merge them into one function if possible, this way we have chance to simply add an option to the function(instead of three places) to determine if use sigmoid or not, since using them gets better mAP but we get better visualizations without it.

@glenn-jocher
Copy link
Member Author

@Laughing-q yes I think on a mathematical level this PR does make sense, it's taking all the values that range from -inf to +inf and placing the threshold at 0, so there will be a better dynamic range on the op than if we sigmoid from 0 to 1 and then do the threshold at 0.5.

The mAP drops are in the Ultralytics mAP but the COCO mAP is mostly the same, and the visual results do look better, less discretization, so let's merge this.

@glenn-jocher glenn-jocher merged commit b10e0f3 into main Jun 25, 2024
16 checks passed
@glenn-jocher glenn-jocher deleted the segment-fix branch June 25, 2024 09:53
@glenn-jocher
Copy link
Member Author

@zxDeepDiver PR merged! Thank you for your contributions.

@glenn-jocher
Copy link
Member Author

@Laughing-q yes the multiple mask processing functions are too many, I agree, I think there are at least two because of the order of processing the upsample, either before or after the mask processing and depending on if it's retina=True or not, but it would be nice to unify them.

@Alarmod
Copy link
Contributor

Alarmod commented Jul 6, 2024

@glenn-jocher Maybe this fix can be made optional? My previously trained neural network, focused on working with ultra-small objects, shows a lower quality...

@Alarmod
Copy link
Contributor

Alarmod commented Jul 6, 2024

pip3 install -U ultralytics==8.2.42

predict_t2_brain_512
Precision --- 0.982777
Recall --- 0.981744
F1 98.22602283 (multiplied by 100.0)

predict_t2_ischemia
Precision --- 0.997980
Recall --- 0.961361
F1 97.93283058

pip3 install -U ultralytics==8.2.43

predict_t2_brain_512
Precision --- 0.975905
Recall --- 0.985638
F1 98.07473530

predict_t2_ischemia
Precision --- 0.971908
Recall --- 0.961250
F1 96.65496198

All F1 values worse on the new version

@glenn-jocher
Copy link
Member Author

Hi @Alarmod,

Thank you for sharing your detailed results. It appears that the recent update has impacted the performance metrics of your model, particularly the F1 scores. We understand how crucial these metrics are for your application, especially when dealing with ultra-small objects.

To address this, we can consider making the recent fix optional. This would allow users to choose whether to apply the sigmoid operation based on their specific use case.

In the meantime, you can revert to the previous version (8.2.42) to maintain your model's performance. If you could provide a minimum reproducible example of your code, it would help us investigate the issue further and ensure that any changes we make will not negatively impact your use case. You can find more details on how to create a reproducible example here.

Additionally, please ensure that you are using the latest versions of all dependencies to rule out any compatibility issues.

Thank you for your patience and understanding. We are committed to improving the performance and flexibility of our models and appreciate your feedback.

Alarmod added a commit to Alarmod/MRI_MedicalAnalysis that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants