LdDl / go-darknet

Go bindings for Darknet (YOLO v4 / v7-tiny / v3)
Apache License 2.0
82 stars 19 forks source link

DarknetImage move float conversion into c code #25

Closed lian closed 2 years ago

lian commented 2 years ago

imgTofloat32 + fill_image_f32 took more than double the time since tofloat created needless allocations and iterate over each pixel, and fill_image in c then iterate over each pixel*3 again just to move it into the c image.

also add ImageRGBA2Float32 to optionally skip the draw.Copy call.

LdDl commented 2 years ago

@lian , thanks for PR I hope everything else works as intended)

I'll take a look into commit soon

p.s. some benchmarks would be great to see also :) (what performance gain would we expect?)

lian commented 2 years ago
name              old time/op    new time/op    delta
Image2Float32-32    7.98ms ± 4%    5.19ms ± 9%  -35.04%  (p=0.000 n=10+10)

name              old alloc/op   new alloc/op   delta
Image2Float32-32    12.0MB ± 0%     1.7MB ± 0%  -85.71%  (p=0.000 n=9+9)

name              old allocs/op  new allocs/op  delta
Image2Float32-32      7.00 ± 0%      3.00 ± 0%  -57.14%  (p=0.000 n=10+10)
LdDl commented 2 years ago

approved and merged next action would be updating release tag)

Thank you for PR