AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.66k stars 7.96k forks source link

YOLO format conversation #6797

Open saikrishnadas opened 3 years ago

saikrishnadas commented 3 years ago

I have a few annotations that is originally in .csv format. I would need to convert it to yolo darknet format inorder to train my model with yolov4. my .cvs file : Screenshot (120)

YOLO format is : object-class x y width height

where, object_class, widht, height is know from my .csv format. But finding x,y is confusing .Note that x and y are center of rectangle (are not top-left corner).

@AlexeyAB

stephanecharette commented 3 years ago

The normalized label format is described on this page, along with some examples: https://www.ccoderun.ca/programming/2019-08-18_Darknet_training_images/ (Scroll down towards the bottom.)

saikrishnadas commented 3 years ago

@stephanecharette my question is, how will we get the center_x and center_y from the x_min,x_max,y_min,y_max? The document explains the conversion of center_x / the image pixel

stephanecharette commented 3 years ago

If the center is at (10, 10) and the width is 4, height is 4, then from the center to the left is 10 - (4/2), and from the center the right is 10 + (4/2), right? Same with top and bottom.

I strongly suggest you go back and re-read that page carefully. It explains how to get from X and Y coordinates to the normalized values. So if you reverse the process, you also can go from normalized values back to X and Y coordinates.

saikrishnadas commented 3 years ago

@stephanecharette I clearly understand what you saying but i dont have center points. I have only the top_right,bottom_right,top_left_bottom_left which is x_min,x_max,y_min,y_max in my .csv file

stephanecharette commented 3 years ago

You're kidding, right?

stephanecharette commented 3 years ago

If you have all those, then obviously you also have the center points. Add another column to your csv file, and do the math to find the center point. x1 + x2 / 2, same with y.

saikrishnadas commented 3 years ago

Sure

stephanecharette commented 3 years ago

Did a little graph to help visualize the problem: image (the center is at 4,4)

So once normalized, you should have:

saikrishnadas commented 3 years ago

@stephanecharette I really appreciate your effort. My image size is 1020 x 720p so, w = obj_w/1020 and h = obj_h/720 right ? or shld it be w = obj_w/480 and h = obj_h/480 as im going to train it on 480x480 yolov4 ?

lsd1994 commented 3 years ago

w = obj_w/1020 and h = obj_h/720

saikrishnadas commented 3 years ago

Can't open label file. (This can be normal only if you use MSCOCO): data/obj/Avacado_retraining__172.txt

I get this error

@AlexeyAB @stephanecharette