ferraridamiano / yolo_flutter

MIT License
25 stars 3 forks source link

No bounding boxes drawn on iOS #4

Closed codscino closed 4 months ago

codscino commented 10 months ago

I am running the example package with yolov8n and this photo(https://www.pexels.com/photo/brown-tabby-cat-2071882/) on iOS simulator iPhone 14 iOS 17 and no bounding boxed is drawn even if in the terminal it says : NMS time: 14 ms, Detected 1 bboxes.

There was another error about photo permission, I just added this in the iOS/Runner/Info.plist file: `NSPhotoLibraryUsageDescription

We require access to your photo library to enable photo selection within the app.` I have the same problem with a physical iPhone 11.
ferraridamiano commented 10 months ago

Are you using the latest version of this code and the latest version of ultralytics? Because recently there was a change about the output format of the model and the output needed to be scaled up. Could you try printing the detected bounding box?

codscino commented 10 months ago

Yes I am using last version of your code and ultralytics, I have generated the model with this python script:

from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n.pt')  # load an official model

# Export the model
model.export(format='tflite')

I got two models: yolov8n_float16.tflite, yolov8n_float32.tflite. I have then put the float32 in the assets/models folder and I renamed it yolov8n.tflite.

I added a debug break point in home_page.dart at line 176 just after the debug print and by printing on the debug console this.bboxes I got this:

this.bboxes
List (1 item)
[0]: List (84 items)
[0]: 535.5945888519287
[1]: 846.0391759872437
[2]: 921.109838104248
[3]: 1312.670373916626
[4]: 0.0001931501756189391
[5]: 0.000020750530893565156
[6]: 0.00000545352122571785
[7]: 0.000002501122480680351
[8]: 0.0000021792043298773933
[9]: 7.737016858300194e-7
[10]: 0.0000012389774610710447
[11]: 9.56103249905027e-8
[12]: 2.909093836933607e-7
[13]: 0.000004615243142325198
[14]: 0.000007136276963137789
[15]: 0.000005957605026196688
[16]: 0.00000458114027424017
[17]: 0.000029978993552504107
[18]: 0.0038761773612350225
[19]: 0.7701735496520996
[20]: 0.009342959150671959
[21]: 0.0006671288283541799
[22]: 0.00032755776192061603
[23]: 0.0001866855309344828
[24]: 0.00011910011380678043
[25]: 0.004815025720745325
[26]: 0.00034990347921848297
[27]: 0.0020033963955938816
[28]: 0.00004043157969135791
[29]: 0.00022256889496929944
[30]: 0.00009807602327782661
[31]: 0.000018544087652117014
[32]: 0.00016369290824513882
[33]: 0.0000030387118385988288
[34]: 0.0000010626005177982734
[35]: 3.2828754115143965e-7
[36]: 0.000010484812264621723
[37]: 7.153626597755647e-7
[38]: 1.70493933637772e-7
[39]: 0.0000012640369959626696
[40]: 0.0000012408670500008157
[41]: 8.098925832200621e-7
[42]: 0.000014372645637195092
[43]: 0.000027790052627096884
[44]: 0.00001994383092096541
[45]: 0.000052814302762271836
[46]: 0.000004130337856622646
[47]: 0.00000441787096860935
[48]: 0.000004671227088692831
[49]: 0.000027812562620965764
[50]: 0.000007393645319098141
[51]: 0.00004386163709568791
[52]: 0.000126130020362325
[53]: 0.00003026737795153167
[54]: 0.00019261243869550526
[55]: 6.322464969343855e-7
[56]: 0.000007536322300438769
[57]: 0.00013020205369684845
[58]: 0.00009893315291265026
[59]: 0.00017033450421877205
[60]: 0.00020136844250373542
[61]: 0.00006610230047954246
[62]: 0.0004045117530040443
[63]: 0.00039409843157045543
[64]: 0.00001897716174426023
[65]: 0.000025670909963082522
[66]: 0.00010037622996605933
[67]: 0.0007863538921810687
[68]: 0.000016214742572628893
[69]: 0.000008513539796695113
[70]: 0.0001223188010044396
[71]: 0.000005689603767677909
[72]: 0.000021303892935975455
[73]: 0.0000029030622954451246
[74]: 0.000007561079200968379
[75]: 0.00005132010846864432
[76]: 0.00007539207581430674
[77]: 0.000014708485650771763
[78]: 0.000015371204426628537
[79]: 0.0005050296313129365
[80]: 0.000011591712791414466
[81]: 0.0010963545646518469
[82]: 0.0000032740008464315906
[83]: 0.000006714094524795655

P.S. Sometimes it does not detect any bounding boxes, but after a few tries it finds one

ferraridamiano commented 10 months ago

How to interpret this data? The first 4 cells refer respectively to the x, y, width, and height of the bounding box. But they are scaled, it would be more interesting to see the normalized version, you can print the bboxes variables after the nms operation inside the postprocess function in the yolo.dart file. The other 80 cells refer to the class probabilities. In your case the class with more probabilities is on cells 19, you have to subtract 3 (because the first cells are for the bbox position and size) and you get 16 which corresponds to the cat which is right (see the labels.dart file).

That said, I'm not sure why it's not showing the bounding box, maybe it is because it is larger than the image itself, could you try printing the normalized version of the bounding box as suggested above? Does this happen just with this image or also with all the images?

ferraridamiano commented 4 months ago

Closing. I did not receive any answers after 7 months, I suppose it is resolved