ermig1979 / Synet

A small framework to infer neural network
MIT License
140 stars 26 forks source link

No objects detected with yolov5 model #29

Open trlsmax opened 2 years ago

trlsmax commented 2 years ago

I trained a custom model with yolov5 and export to onnx format, then convert to synet format. The following code detected nothing, but the onnx model works fine with detect.py of yolov5.

   Net net;
    net.Load("test.xml", "test.bin");

    net.Reshape(1920, 1920, 1);

    Shape shape = net.NchwShape();

    View original;
    original.Load("test0.png");

    View resized(shape[3], shape[2], original.format);
    Simd::Resize(original, resized, ::SimdResizeMethodArea);

    net.SetInput(resized, 0.0f, 255.0f);

    net.Forward();

    Regions objects = net.GetRegions(original.width, original.height, 0.5f, 0.5f);
    uint32_t white = 0xFFFFFFFF;
    for (size_t i = 0; i < objects.size(); ++i)
    {
        const Region & object = objects[i];
        ptrdiff_t l = ptrdiff_t(object.x - object.w / 2);
        ptrdiff_t t = ptrdiff_t(object.y - object.h / 2);
        ptrdiff_t r = ptrdiff_t(object.x + object.w / 2);
        ptrdiff_t b = ptrdiff_t(object.y + object.h / 2);
        Simd::DrawRectangle(original, l, t, r, b, white);
    }
    original.Save("test0r.ppm");

    return 0;
ermig1979 commented 2 years ago

Hi! Could you give me this model to check correctness of it's conversion?

trlsmax commented 2 years ago

Just send you the model by email.

ermig1979 commented 2 years ago

I added YoloV5Decoder to parse YoloV5 output:

#include "Synet/Decoders/YoloV5.h"

Synet::YoloV5Decoder decoder;
decoder.Init();

Regions objects = decoder.GetRegions(net, original.width, original.height, 0.5f, 0.5f)[0];
trlsmax commented 2 years ago

Thank you. But I still can't get any detection.

int main(int argc, char* argv[])
{
    Net net;
    net.Load("test.xml", "test.bin");

    net.Reshape(1920, 1920, 1);

    Shape shape = net.NchwShape();

    View original;
    original.Load("test0.png");

    View resized(shape[3], shape[2], original.format);
    Simd::Resize(original, resized, ::SimdResizeMethodArea);

    net.SetInput(resized, 0.0f, 255.0f);

    net.Forward();

    Synet::YoloV5Decoder decoder;
    decoder.Init();

    Regions objects = decoder.GetRegions(net, original.width, original.height, 0.5f, 0.5f)[0];
    // objects.size() == 0 here

    uint32_t white = 0xFFFFFFFF;
    for (size_t i = 0; i < objects.size(); ++i)
    {
        const Region& object = objects[i];
        ptrdiff_t l = ptrdiff_t(object.x - object.w / 2);
        ptrdiff_t t = ptrdiff_t(object.y - object.h / 2);
        ptrdiff_t r = ptrdiff_t(object.x + object.w / 2);
        ptrdiff_t b = ptrdiff_t(object.y + object.h / 2);
        Simd::DrawRectangle(original, l, t, r, b, white);
    }
    original.Save("test0r.ppm");

    return 0;
}