hailo-ai / hailo_model_zoo

The Hailo Model Zoo includes pre-trained models and a full building and evaluation environment
MIT License
308 stars 44 forks source link

yolov8n post processing #62

Open RiccardoSegala04 opened 1 year ago

RiccardoSegala04 commented 1 year ago

Hello,

I retrained a yolov8n network using the instructions i found on hailo model zoo github. Now i have a .hef network, but when I try to infer with this model I get in output 6 vectors of different dimensions. What's the correct way to translate them in order to get a list of actual detections?

nina-vilela commented 1 year ago

Hi @RiccardoSegala04,

The Hailo ModelZoo has an evaluation CLI tool called eval, it can be used for both calculating accuracy and visualizing results.

To get more information about the eval tool's usage, run hailomz eval -h

And you can find the code for the ModelZoo's detection evaluation here.

We also offer standalone examples for yolov8 in HACER. They include inference, postprocessing, and visualization:

Let me know if anything is unclear.

RiccardoSegala04 commented 1 year ago

Thank you for your response.

I tried using hailomz eval command, and on the model i downloaded from hailo model zoo repository it works. Our model is a retrained one with less prediction classes than the original one (7 classes), and it does not work with that command.

hailomz eval --hef /path/to/hef --target hailo8 --data-path /path/to/data --visualize yolov8n

I get this error:

score = tf.reshape(node, (-1, fm_size_h * fm_size_w, num_classes))
ValueError: Dimension size must be evenly divisible by 512000 but is 358400

I thought it was because of the different number of classes, so i tried to use the python example you showed me. Even there i needed to change the shape of the tensors i get from the hailo, but i can't get any result, like the network is imported in a wrong way...

What should i do?

tmyapple commented 1 year ago

Hi @RiccardoSegala04 The model-zoo models are being configured through YAML files, yolov8n configuration can be seen here, and it assumes you run on COCO dataset (80 classes). pleas try to add the right number of classes into this YAML: evaluation: classes: 7

Also - the shapes might be wrong because different order of parsing, in the yolov8n.yaml you can see what layers were defined as the outputs... in the info you will see the output shapes output_shape: 80x80x80, 80X80X64, 40X40X80, 40X40X64, 20X20X80, 20X20X64

which our model zoo expects

RiccardoSegala04 commented 1 year ago

And if i wanted to use my model with the python examples the only things i should change in the code are the network output shapes?

nina-vilela commented 1 year ago

@RiccardoSegala04 For the python example you need to pass the --classes-num flag with the relevant number of classes

RiccardoSegala04 commented 1 year ago

I did that but it didn't work because the output shape of my model is different, because the number of classes is different. So i changed that in the code, and it runs, but it seems like the network is imported in the wrong way..

nina-vilela commented 1 year ago

@RiccardoSegala04

We will be happy to assist you with it through our ticketing system. Click here to open a ticket.

RiccardoSegala04 commented 1 year ago

thank you

tylertroy commented 1 year ago

You can modify yolo_inference.py lines 152 through 157 with the following sed command to recover the functionality of the --class-num CLI argument .

sed -i 's/, 80\]/, num_of_classes\]/g' yolo_inference.py

If you want to revert for whatever reason, run

git checkout yolo_inference.py