jveitchmichaelis / deeplabel

A cross-platform desktop image annotation tool for machine learning
205 stars 39 forks source link

Yolov4-tiny-3l model doesn't work #26

Closed lukaswozniak closed 2 years ago

lukaswozniak commented 2 years ago

After I configure object detector and run it on any image it doesn't show any new annotations.

I tried "Set threshold" to 0,01 but it didn't change anything. Setting it to CPU also doesn't help.

My configuration:

image

After pressing the magic wand button (no new annotation added):

image

Proof that my model is able to detect the object:

image

Is there anything I can do to debug this more? Please help

jveitchmichaelis commented 2 years ago

What's the pretrained model you're using for this (eg from the darknet model zoo)? I can check using that. It seems to run the model OK from the log output - e.g. nothing has crashed... but if things were detected you'd see that in the log.

I've not had any trouble with yolov4-tiny using the COCO val set so would be good to check.

lukaswozniak commented 2 years ago

cfg: https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov3-tiny_3l.cfg pre-trained weights: https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.conv.29

jveitchmichaelis commented 2 years ago

Sure the config is correct? That's a yolov3 and the weights are v4. I'll double check on the latest release, maybe something's affected inference - yolov4 tiny definitely works.

Can you check with e.g. the pre-trained COCO model? e.g.

yolov4-tiny.weights yolov4-tiny.cfg

jveitchmichaelis commented 2 years ago

Sure the config is correct? That's a yolov3 and the weights are v4. I'll double check on the latest release, maybe something's affected inference - yolov4 tiny definitely works.

Can you check with e.g. the pre-trained COCO model? e.g.

yolov4-tiny.weights yolov4-tiny.cfg coco.names

make a project with some random test images of everyday things and try running that.

lukaswozniak commented 2 years ago

I pasted wrong cfg, should be this one: https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-tiny-3l.cfg Im sure its correct, definitely works when Im using it with the darknet.exe cmd line tool.

I will check tomorrow with COCO model.

jveitchmichaelis commented 2 years ago

Great, thanks. I don't know why a custom model would fail, but perhaps that's the issue. Though OpenCV would probably error out if it failed to load properly.

lukaswozniak commented 2 years ago

I found what is the bug, but I'm not sure how to fix it in code. My network uses size 960x960, not the default 416x416. I even can see that the program recognizes it correctly here:

image

But after some debugging I found that actual values used was 416x416. Adding this code to DetectorOpenCV::inferDarknet fixes it for me:

        std::cout << "input_width: " << input_width << std::endl; // prints 416
        std::cout << "input_height: " << input_height << std::endl; // prints 416
        input_width = 960;input_height = 960; // fix working only in my case
        auto input_size = cv::Size(input_width, input_height);

        bool swap_rb = true; // BGR->RGB?
        bool crop = false; // Use the entire image
        auto blob = cv::dnn::blobFromImage(image, scale_factor, input_size, mean, swap_rb, crop);

I don't know the project well enough to make actual fix, but if you want I may try.

jveitchmichaelis commented 2 years ago

Merged, thanks!