Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific format of annotation #60

Closed
ycui123 opened this issue Jul 2, 2018 · 69 comments
Closed

Specific format of annotation #60

ycui123 opened this issue Jul 2, 2018 · 69 comments
Labels
Solved The problem is solved using the correct settings

Comments

@ycui123
Copy link

ycui123 commented Jul 2, 2018

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

@AlexeyAB
Copy link
Owner

AlexeyAB commented Jul 2, 2018

.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

@ycui123
Copy link
Author

ycui123 commented Jul 2, 2018

Thank you @AlexeyAB . This is very helpful.

@ycui123
Copy link
Author

ycui123 commented Jul 11, 2018

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?

@ycui123
Copy link
Author

ycui123 commented Jul 11, 2018

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 .

@ycui123
Copy link
Author

ycui123 commented Jul 11, 2018

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.

@AlexeyAB
Copy link
Owner

@ycui123

@ycui123
Copy link
Author

ycui123 commented Jul 11, 2018

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

@AlexeyAB AlexeyAB added the Solved The problem is solved using the correct settings label Jul 11, 2018
@ycui123
Copy link
Author

ycui123 commented Jul 11, 2018

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

@koutini
Copy link

koutini commented Mar 12, 2019

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

@sarratouil
Copy link

@koutini i have the same problem

@sarratouil
Copy link

@koutini please help me to resolve it

@koutini
Copy link

koutini commented Mar 12, 2019

@sarratouil thank you for the support

@sarratouil
Copy link

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

@AlexeyAB
Copy link
Owner

@koutini @sarratouil Hi,

  • What dataset do you use?

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

@sarratouil
Copy link

@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

@sarratouil
Copy link

@AlexeyAB please help me to resolve it

@koutini
Copy link

koutini commented Mar 12, 2019

@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

@sarratouil
Copy link

sarratouil commented Mar 12, 2019

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

@koutini
Copy link

koutini commented Mar 12, 2019

@sarratouil I told you

@koutini
Copy link

koutini commented Mar 12, 2019

@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

@AlexeyAB
Copy link
Owner

@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

@sarratouil
Copy link

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

@sarratouil
Copy link

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

@AlexeyAB
Copy link
Owner

@sarratouil

  1. Try to use this repository: https://github.com/thtrieu/darkflow there is about converting Yolo to TensorFlow: How to convert darknet model to tensorflow model thtrieu/darkflow#527

  2. Or just use OpenCV for android https://opencv.org/releases.html and use your yolo-tiny-obj.cfg / yolo-tiny-obj.weights by using these examples:


Also you can look at these repos:

@koutini
Copy link

koutini commented Mar 17, 2019

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 ?

@AlexeyAB
Copy link
Owner

@koutini Hi,

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

@koutini
Copy link

koutini commented Mar 17, 2019

image

@cindyweng
Copy link

cindyweng commented May 19, 2020

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

@MAJEEDI
Copy link

MAJEEDI commented May 19, 2020 via email

@balajib363
Copy link

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.

@stevedepp
Copy link

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 ?

@amashi01
Copy link

amashi01 commented Jul 10, 2020

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}]}

@Emirismail
Copy link

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

@sarratouil Could you please share your code?

@saikrishnadas
Copy link

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 :)

@mk-hasan
Copy link

mk-hasan commented Oct 7, 2020

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.

@kishore-jd
Copy link

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

@saikrishnadas
Copy link

@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 ?

@kishore-jd
Copy link

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

@ForceQuell
Copy link

ForceQuell commented Oct 22, 2020

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?

@masoodazhar
Copy link

masoodazhar commented Oct 27, 2020

.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:

@stephanecharette
Copy link

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

@annezao
Copy link

annezao commented Apr 3, 2021

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?

@stephanecharette
Copy link

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.

@muhammadhamzahabibhashmi

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

@stephanecharette
Copy link

The format is described here in details: https://www.ccoderun.ca/programming/darknet_faq/#darknet_annotations

@masoodazhar
Copy link

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))

@masoodazhar
Copy link

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))

@Riankk123
Copy link

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 ?

@brandhsu
Copy link

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

darknet_format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Solved The problem is solved using the correct settings
Projects
None yet
Development

No branches or pull requests