luxonis / yolo2openvino

YoloV3, YoloV4, YoloV3-tiny, and YoloV4-tiny conversion to Tensorflow and OpenVINO.
MIT License
10 stars 9 forks source link

How to Transform yolov4-custom to .pb #3

Open frmunozForcast opened 2 years ago

frmunozForcast commented 2 years ago

Hi,

I'm using a darknet yolov4-custom model for detecting small objects modified according to this guide darknet-small-objects, which we plan to run on a depthAI device (we will later change to yolov4-tiny, also customized). However, I'm having troubles to adapt your code so I can convert to .pb format (Im following your colab guide to transform darknet to blob)

So far I understand a bit how your code works to transform darknet yolo to tensorflow .pb and I've managed to modify the code for custom classes, anchors and masks. However, one of the modifications made on my custom yolo was set layers = 23 instead of layers = 54 in the route before the firs yolo layer (L895 in custom .cfg). As I understand, this means that I have to replace up_route_54 in L100 and L102 with up_route_23, but I do not know how to capture up_route_23, any guide or idea?

I've also modified the stride = 2 to stride = 4 in the line just before the modified route. Do I have to change something else related to this stride?.

Thanks!

tersekmatija commented 2 years ago

Hey @frmunozForcast , I'd suggest you stick with YoloV4-tiny for depthai devices if you want the model to work in real time.

However, if you still want to convert the model, you'll need the following changes:

Best, Matija

frmunozForcast commented 2 years ago

Hey @frmunozForcast , I'd suggest you stick with YoloV4-tiny for depthai devices if you want the model to work in real time.

Yes, we will probably change to Yolov4-tiny, however, we would compare performance between using 2 yolo layers to 3 yolo layers for our specific scenario, in which case i'll also need to change other parts of the code as well.

However, if you still want to convert the model, you'll need the following changes:

  • Delete L65 and add up_route_23=net in L61. That is right before

      net = _yolo_res_Block(net,128,8,data_format)
  • Replace up_route_54 with up_route_23 in L100 and L102

  • Since _upsample in L100 reads the shape from up_route_23, there's no need in setting another strides to 4 like in CFG file.

  • Set strides=4 in L165

Thanks for the tips!, ill try this

tersekmatija commented 2 years ago

I think adding 3 layers shouldn't be problematic as well. If you edit the code and make it controllable by a flag, feel free to make a pull request :)

frmunozForcast commented 2 years ago

Yes it wasn't that difficult, I managed to add both changes on a fork adding an optional flag that points to a config file where the specifics for custom model are defined. However, I have jet to confirm that the models are correctly converted. Once I've checked that, ill send the pull request.

Thank you for your help!