AlexeyAB/Yolo_mark

Specific format of annotation

ycui123 opened this issue ยท 69 comments

Could you please tell me the format of annotation? I generated my own dataset and I want to train it. I know exactly where my objects are in the image. In that case, I don't want to manually generate annotation. I can write some code to do it for me if I know the format of annotation for YOLO v3. Thank you

.txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line: <object-class> <x> <y> <width> <height>

Where:

  • <object-class> - integer number of object from 0 to (classes-1)
  • <x> <y> <width> <height> - float values relative to width and height of image, it can be equal from (0.0 to 1.0]
  • for example: <x> = <absolute_x> / <image_width> or <height> = <absolute_height> / <image_height>
  • atention: <x> <y> - are center of rectangle (are not top-left corner)

For example for img1.jpg you will be created img1.txt containing:

1 0.716797 0.395833 0.216406 0.147222
0 0.687109 0.379167 0.255469 0.158333
1 0.420312 0.395833 0.140625 0.166667

https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

  1. Create file obj.names in the directory build\darknet\x64\data\, with objects names - each in new line

  2. Create file obj.data in the directory build\darknet\x64\data\, containing (where classes = number of objects):

classes= 2
train  = data/train.txt
valid  = data/test.txt
names = data/obj.names
backup = backup/
  1. Put image-files (.jpg) of your objects in the directory build\darknet\x64\data\obj\

  2. You should label each object on images from your dataset. Use this visual GUI-software for marking bounded boxes of objects and generating annotation files for Yolo v2 & v3: https://github.com/AlexeyAB/Yolo_mark

It will create .txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line: <object-class> <x> <y> <width> <height>

Where:

  • <object-class> - integer number of object from 0 to (classes-1)
  • <x> <y> <width> <height> - float values relative to width and height of image, it can be equal from (0.0 to 1.0]
  • for example: <x> = <absolute_x> / <image_width> or <height> = <absolute_height> / <image_height>
  • atention: <x> <y> - are center of rectangle (are not top-left corner)

For example for img1.jpg you will be created img1.txt containing:

1 0.716797 0.395833 0.216406 0.147222
0 0.687109 0.379167 0.255469 0.158333
1 0.420312 0.395833 0.140625 0.166667
  1. Create file train.txt in directory build\darknet\x64\data\, with filenames of your images, each filename in new line, with path relative to darknet.exe, for example containing:
data/obj/img1.jpg
data/obj/img2.jpg
data/obj/img3.jpg

Thank you @AlexeyAB . This is very helpful.

Hi @AlexeyAB ,

I generated annotations by a script. But when I try to test my model. I cannot see a bounded box on my test data. Is it because I didn't use the tool to generate bounded box for my training data?

I only have one class and I trained for 4000 iterations. I used the command line to test.

  • darknet.exe detector test data/obj.data yolo-obj.cfg yolo-obj_4000.weights -thresh 0.25 E:\darknet\build\darknet\x64\data\obj_test\11.jpg -ext_output

I only got "E:\darknet\build\darknet\x64\data\obj\11.jpg: Predicted in 0.060051 seconds." without any bounded boxes and coordinates of objects.

Thank you .

Alright, I think the problem is the model is not predicting. That's weird. I trained for 4000 iterations and got 0.7 loss.

I'm not getting results even when I test on training data.

@ycui123

Thank you for your reply. I think I found the bug. I labelled my object wrong somehow which leads to useless traning.

But does Yolo_mark resize the image before it does the mark?

Edited: My bad. It doesn't. I reversed x and y and it works! Thanks a lot

hello, i have annotation with three valuers (example 156 111 111) and i i don't understand how to convert annotation with three valuers to yolo format๏ปฟ

@koutini i have the same problem

@koutini please help me to resolve it

@sarratouil thank you for the support

@AlexeyAB @ycui123 @ido-ran @RRMoelker how can i convert to format yolo this format of annotations
please help me
annot
annot
annot

@koutini @sarratouil Hi,

  • What dataset do you use?

  • What do these 3 values mean? Where is: class_id, x, y, width and height?

@AlexeyAB i use this dataset to train to detect iris
i download this dataset from " https://web.inf.ufpr.br/vri/databases/iris-location-annotations/ "
it is annoted dataset but i hav'nt any idea about this 3 values

@AlexeyAB please help me to resolve it

@AlexeyAB thank you so much for your answer ,
we use iris data set annotation for that we can get always square to detect the position iris in an image , actually i don't understand what represents each number in this annotation

@AlexeyAB may be 1st ,2nd values are the coordinates of the centre of square
and 3rd is (width and height)

@sarratouil I told you

@AlexeyAB also may be 1st ,2nd values are coordinates of the first point when the writer click in the image and 3rd is width and height

@koutini @sarratouil

I just don't see the link to IRIS images.

Every .txt file has the following contents: image irisX irisY irisR

So you should write your code on Bash/Python/C... for converting
from irisX irisY irisR
to 0 irisX/image_width irisY/image_height irisR/image_width irisR/image_height

Just for example, you can look at this script - how to read CSV files on bash: https://github.com/AlexeyAB/darknet/blob/master/scripts/windows/otb_get_labels.sh

@AlexeyAB
Thank you very much
I write a code with python and it work very good .

@AlexeyAB you have any idea how i can convert anymy yolo-tiny-obj that i trained it to TensorFlow to use on Android platforms

dear @AlexeyAB hello ,
after the train with darknet and yolo the detection box it not exact my question is : anchors can be the raison of this problem ?

@koutini Hi,

What do you mean?
Can you show screenshot of example?

image
my objective is to detect iris in an image but i don't get the exact result after the train . anchors can be the raison of this problem ?

@koutini

  • Do you use yolov2.cfg?

  • I think anchors are not the main problem. Although you can try to set the square anchors and train the model again - just set anchors anchors = 0.738,0.738, 2.422,2.422, ... and train again

  • Better to use yolov3.cfg

i use tiny-yolo.cfg i will try to fix it thank you so much !

how can i decrease the number of layers to 9 when i use yolov3.cfg ?

i want yolo to just list possible objects in in an image ... how to do that in traditional yolo implementation ?

@AliYar-Khan What do you mean by *just list possible objects in an image *?

I am having this problem as well using Google colab:

Loading weights from darknet19_448.conv.23...
seen 32
Done!
Learning Rate: 0.001, Momentum: 0.9, Decay: 0.0005
Resizing
608 x 608

Wrong annotation: x = 0, y = 0, < 0 or > 1

Wrong annotation: x = 0, y = 0, < 0 or > 1

Then memory dump

I only have one class and I trained for 4000 iterations. I used the command line to test.

* darknet.exe detector test data/obj.data yolo-obj.cfg yolo-obj_4000.weights -thresh 0.25 E:\darknet\build\darknet\x64\data\obj_test\11.jpg -ext_output

I only got "E:\darknet\build\darknet\x64\data\obj\11.jpg: Predicted in 0.060051 seconds." without any bounded boxes and coordinates of objects.

Thank you .

How do we run this command on any image who's path is not located in darknet folder?

.txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line: <object-class> <x> <y> <width> <height>

Where:

* `<object-class>` - integer number of object from **`0` to `(classes-1)`**

* `<x> <y> <width> <height>` - float values relative to width and height of image, it can be equal from (0.0 to 1.0]

* for example: `<x> = <absolute_x> / <image_width>` or `<height> = <absolute_height> / <image_height>`

* atention: `<x> <y>` - are center of rectangle (are not top-left corner)

For example for img1.jpg you will be created img1.txt containing:

1 0.716797 0.395833 0.216406 0.147222
0 0.687109 0.379167 0.255469 0.158333
1 0.420312 0.395833 0.140625 0.166667

https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

  1. Create file obj.names in the directory build\darknet\x64\data\, with objects names - each in new line
  2. Create file obj.data in the directory build\darknet\x64\data\, containing (where classes = number of objects):
classes= 2
train  = data/train.txt
valid  = data/test.txt
names = data/obj.names
backup = backup/
  1. Put image-files (.jpg) of your objects in the directory build\darknet\x64\data\obj\
  2. You should label each object on images from your dataset. Use this visual GUI-software for marking bounded boxes of objects and generating annotation files for Yolo v2 & v3: https://github.com/AlexeyAB/Yolo_mark

It will create .txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line: <object-class> <x> <y> <width> <height>
Where:

  • <object-class> - integer number of object from 0 to (classes-1)
  • <x> <y> <width> <height> - float values relative to width and height of image, it can be equal from (0.0 to 1.0]
  • for example: <x> = <absolute_x> / <image_width> or <height> = <absolute_height> / <image_height>
  • atention: <x> <y> - are center of rectangle (are not top-left corner)

For example for img1.jpg you will be created img1.txt containing:

1 0.716797 0.395833 0.216406 0.147222
0 0.687109 0.379167 0.255469 0.158333
1 0.420312 0.395833 0.140625 0.166667
  1. Create file train.txt in directory build\darknet\x64\data\, with filenames of your images, each filename in new line, with path relative to darknet.exe, for example containing:
data/obj/img1.jpg
data/obj/img2.jpg
data/obj/img3.jpg

Thank you for this. Doesn't YOLOv2 need to know the appropriate grid cell number?
The final label will be something like 7x7x125, where only the correct grid cell number
will be labeled correctly. How does this annotation convert into appropriate label?

If you need to format open image to Yolo v3 with parent class of subclass dataset, you can have a look

https://github.com/mk-hasan/OpenImage-Data-convert-YOLOV3

Hi, @AlexeyAB !
I have some questions about anotation.

Is th format of txt annotation file, <class> <x> <y> <width> <height> fixed?
How does it affect adaptability for some datasets.

How about another form I wanna use? e.g.

Am I able to assign a annotation form?

And I use YOLOv3 on Ubuntu 16.04 LTS.
Thank you.

Hi, @AlexeyAB !
I have some questions about anotation.

Is th format of txt annotation file, <class> <x> <y> <width> <height> fixed?
How does it affect adaptability for some datasets.

How about another form I wanna use? e.g.

Am I able to assign a annotation form?

And I use YOLOv3 on Ubuntu 16.04 LTS.
Thank you.

  1. i think it must be the same as Yolo only accept this format.
  2. You can not use another form, why dont you just transform your format to yolo format?
  3. Can you explain more what did you want to say?

Everyone: It's very easy to see what format Yolo uses. Just look here for the Yolo_mark math that calculates the .txt file data:

Yolo_mark/main.cpp

Lines 527 to 543 in 3e2f234

// store coords to [image name].txt
for (auto &i : current_coord_vec)
{
float const relative_center_x = (float)(i.abs_rect.x + i.abs_rect.width / 2) / full_image_roi.cols;
float const relative_center_y = (float)(i.abs_rect.y + i.abs_rect.height / 2) / full_image_roi.rows;
float const relative_width = (float)i.abs_rect.width / full_image_roi.cols;
float const relative_height = (float)i.abs_rect.height / full_image_roi.rows;
if (relative_width <= 0) continue;
if (relative_height <= 0) continue;
if (relative_center_x <= 0) continue;
if (relative_center_y <= 0) continue;
ofs << i.id << " " <<
relative_center_x << " " << relative_center_y << " " <<
relative_width << " " << relative_height << std::endl;
}

Note: i.abs_rect.x is x1 and i.abs_rect.y is y1 of your box. This code takes the "top left corner" of the box, and adds half the width and height, to get the center.

how can I change the annotation format from

1 0.55625 0.4375 0.1975 0.4

class w1 h1 w2 h2 ...
w, h -width, height of anchor boxes
every annotation is in different note file here
to :

path/to/img1.jpg 50,100,150,200,0 30,50,200,120,3
path/to/img2.jpg 120,300,250,600,2

path to photos w1,h1,w2,h2...,class
here all of the annotations should be in one note file
?

Hey, might be a silly question but where do I put all the bounding boxes txt files? We mentioned the location of images but we did not mention the location of annotations to darknet did we? thanks

@wasp-codes
In the same directory where are images.

Hi, I follow this tutorial but it gives me IoU value of (-) negative or sometimes nan.

@jheanelestrada the nan notation is given when there is no object in that specific region or Intersection over union. I am not sure about the -ve value but i know IoU must be as high as possible its nothing but the accuracy of prediction done or the object detect in that particular region.

Hi, plz can tell me how to read image and annotation file.txt and drawing a bounding box for this: 540 179 80 243 1 0 0 0 0 1 0 for example, any file has rows according to a number of objects in the image.

@jheanelestrada Hi, plz can tell me how to read image and annotation file.txt and drawing a bounding box for this: 540 179 80 243 1 0 0 0 0 1 0 for example, any file has rows according to a number of objects in the image.

Hey, might be a silly question but where do I put all the bounding boxes txt files? We mentioned the location of images but we did not mention the location of annotations to darknet did we? thanks

@wasp-codes
in the same folder as the .jpgs

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.

The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417

Please help how to get a relation between the detected box values and what yolo uses for training.

Hello, Thank you for the instructions. May I confirm? I am putting my custom data into darknet/build/darknet/x64/data/
Then, instructions say "To train on Linux use command: ./darknet detector train data/obj.data yolo-obj.cfg yolov4.conv.137" Are we running from ./darknet or from ~/darknet/build/darknet or from ~/darknet_custom/build/darknet/64 please ?

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.

The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417

Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.

{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}

'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

@AlexeyAB
Thank you very much
I write a code with python and it work very good .

@sarratouil Could you please share your code?

Hey, I would like to know how to calculate .
This is how my data looks like.
Screenshot (120)
With this i could easily find the widht and height but really stuck at finding the x,y that is need to convert to yolo format .

Help is appreciated :)

Hey, I would like to know how to calculate .
This is how my data looks like.
Screenshot (120)
With this i could easily find the widht and height but really stuck at finding the x,y that is need to convert to yolo format .

Help is appreciated :)

Hi, You already have the bounding box information. That should be fine. Now you need to feed the data to yolo and check the code how it takes the data. Maybe I am not sure about your question, otherwise, I could help. Thank you.

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.
The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417
Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.

{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}

'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

i am also facing the same issue

@mk-hasan Yolo takes in this format
My .csv file has these information expect . Yolo takes in center of x and center of y. My data has x_min ,x_max and y_min and y_max. Now how do i calculate the ?

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.

The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417

Please help how to get a relation between the detected box values and what yolo uses for training.
I am also facing the same can you help me

Hi!
Could you tell how axes on image are oriented?
Do they oriented like in 2d-array (origin in left-top corner, X goes down, Y goes right)?
And does it all work for yolov4?

.txt-file for each .jpg-image-file - in the same directory and with the same name, but with .txt-extension, and put to file: object number and object coordinates on this image, for each object in new line:

Where:

- integer number of object from 0 to (classes-1)
- float values relative to width and height of image, it can be equal from (0.0 to 1.0]
for example: = <absolute_x> / <image_width> or = <absolute_height> / <image_height>
for example:
<absolute_x> = (x minimum+<image_width>)/2
= <absolute_x> / <image_width> or = (image_height-1) / <image_height>

atention: - are center of rectangle (are not top-left corner)
For example for img1.jpg you will be created img1.txt containing:

This old thread seems to come up a lot. I've added an entry to the FAQ with an example showing exactly how the numbers all fit together. See this: https://www.ccoderun.ca/programming/darknet_faq/#darknet_annotations

Is it a problem if somehow some values, after calculate to yolo format, look like this:

0 0.67890625 1.287037037037037 0.05364583333333333 0.2555555555555556

the y axis is above 1. Is that alright?

If you're asking, I'm guessing you already know it is a problem. The values are normalized 0...1 so it is impossible to get a value > 1. And since that is the middle coordinate and not an edge of the rectangle, it should be impossible to get exactly 1.0 as well.

I'm not certain what that would do to Darknet during training, but it cannot be good. I wouldn't be surprised if it causes Darknet to crash as it attempts to create a RoI from the image outside of the image boundary.

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.
The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417
Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.

{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}

'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

You have to follow a formula
x = (x1+x1+w1)/2
y = (y1+y1+h1)/2
with open('Annotations.txt', 'a') as file:
file.write(f'{classid} {y/512} {x/512} {(w1+20)/512} {(h1+20)/512}') # where 512 is the image width and height

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.
The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417
Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.
{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}
'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

You have to follow a formula
x = (x1+x1+w1)/2
y = (y1+y1+h1)/2
with open('Annotations.txt', 'a') as file:
file.write(f'{classid} {y/512} {x/512} {(w1+20)/512} {(h1+20)/512}') # where 512 is the image width and height

yes. i have tried this. and this is working fine.
save detected coordinates like. if your image size is 512x470 or else.
just save the detected coordinates like example blow.

x,y,w,h = detected_coordinates # its corrdinates of a bounding box of an object of image
ymid, xmid, height, width = (((1+y1)/2)/y1, ((1+x1)/2)/x1, (y1-1)/y1, (x1-1)/x1)
print('{:0.6f} {:1.6f} {:2.6f} {:3.6f}'.format(xmid, ymid, width, height))

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.
The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417
Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.
{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}
'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

You have to follow a formula
x = (x1+x1+w1)/2
y = (y1+y1+h1)/2
with open('Annotations.txt', 'a') as file:
file.write(f'{classid} {y/512} {x/512} {(w1+20)/512} {(h1+20)/512}') # where 512 is the image width and height

yes. i have tried this. and this is working fine.
save detected coordinates like. if your image size is 512x470 or else.
just save the detected coordinates like example blow.
(y1,x1) = image.shape[:2] # these are width and height of an image
x,y,w,h = detected_coordinates # its corrdinates of a bounding box of an object of image
ymid, xmid, height, width = (((1+y1)/2)/y1, ((1+x1)/2)/x1, (y1-1)/y1, (x1-1)/x1)
print('{:0.6f} {:1.6f} {:2.6f} {:3.6f}'.format(xmid, ymid, width, height))

Hello,
I am trying to automate my annotations. I trained a model which can detect the object, so once an object is detected I am saving its x,y,w,h i.e(left_x: 43 top_y: 102 width: 498 height: 291).
But if I try to open this in Yolo_mark or labelImg I am not able to view it.
From this thread I understood I need to scale in between 0-1, but when I divide it with width or height its not near equal.
The below I got from LabelImg tool in Yolo format.
0.450000 0.515625 0.825000 0.610417
Please help how to get a relation between the detected box values and what yolo uses for training.

Are you able to get the formula? I am also having the same issue.
{'class_id': 0, 'width': 20, 'top': 387, 'height': 74, 'left': 789}, {'class_id': 1, 'width': 25, 'top': 348, 'height': 31, 'left': 805}, {'class_id': 2, 'width': 19, 'top': 447, 'height': 26, 'left': 826}, {'class_id': 4, 'width': 47, 'top': 545, 'height': 33, 'left': 727}, {'class_id': 3, 'width': 32, 'top': 364, 'height': 144, 'left': 896}, {'class_id': 5, 'width': 89, 'top': 246, 'height': 97, 'left': 825}, {'class_id': 7, 'width': 254, 'top': 224, 'height': 388, 'left': 725}
'image_size': [{'width': 1040, 'depth': 3, 'height': 780}]}

You have to follow a formula
x = (x1+x1+w1)/2
y = (y1+y1+h1)/2
with open('Annotations.txt', 'a') as file:
file.write(f'{classid} {y/512} {x/512} {(w1+20)/512} {(h1+20)/512}') # where 512 is the image width and height

yes. i have tried this. and this is working fine.
save detected coordinates like. if your image size is 512x470 or else.
just save the detected coordinates like example blow.

x,y,w,h = detected_coordinates # its corrdinates of a bounding box of an object of image
ymid, xmid, height, width = (((1+y1)/2)/y1, ((1+x1)/2)/x1, (y1-1)/y1, (x1-1)/x1)
print('{:0.6f} {:1.6f} {:2.6f} {:3.6f}'.format(xmid, ymid, width, height))

Does it mean that x_ mid = (left_x + width + left_x)/2 and y_mid = (top_y + height + top_y)/2 .
And bottom_y = top_y + height and right_x = left_x + width . ?
Please help ?

@Riankk123
Format is already stated here: #60 (comment)

darknet_format