AlexeyAB / Yolo_mark

GUI for marking bounded boxes of objects in images for training neural network Yolo v3 and v2
https://github.com/AlexeyAB/darknet
The Unlicense
1.8k stars 680 forks source link

YOLOv4 annotations bounding box #206

Open adnankarol opened 3 years ago

adnankarol commented 3 years ago

@AlexeyAB
Output of YOLO class1: 30% (left_x: 1594 top_y: 5 width: 823 height: 398) class2: 89% (left_x: 1624 top_y: 11 width: 766 height: 384)

Ground Truth File class2 0.6834710743801653 -0.0007513148009012858 0.9954545454545455 0.9984973703981965 class1 0.6875436293114982 0.00983195749251466 0.9105397751844504 0.989553997972583

I need to Transform the Output of YOLO to Ground Truth File ---- MAIN DOUBT

Format for Ground Truth File : x1min y1min x2max y2max

Format of YOLO :

One formula which I had was for YOLO to Ground Truth x1min = (xc - (0.5 * w))/img_w x2max = (xc + (0.5 * w))/img_w y1min = (yc - (0.5 * h))/img_h y2max = (yc + (0.5 * h))/img_h This gave output as class1 0.48863636363636365 -0.485 0.8287190082644628 0.51 class2 0.5128099173553718 -0.4525 0.8293388429752067 0.5075 This is close but not exactly the same as Ground Truth
thegamercoder19 commented 3 years ago

Hi, first you have negative bounding boxes. Try imgaug. x1,y1 is top-most coords and w = x2-x1. Center coords are just x1 + 0.5w. So if you want to convert yolov3 keras format to yolo darknet: import cv2 im = cv2.imread('path/to/your/image.ext') wr, hr = im.shape w = x2-x1 h = y2-y1 cx = x1+0.5*w cy = y1+0.5*h cx, cy = cx / wr, cy / hr w, h = w / wr, h / hr with open("annotation.txt","w+") as f: f.write(f"class {cx} {cy} {w} {h}\n"); f.close()