When you use Yolo-model, you might create annotation labels with Yolo-mark.
For example,
obj.names
- example of list with object names train.txt
- example with list of image filenames for training Yolo model train/
- example of folder that contain images and labels
- *.jpg : example of list of image
- *.txt : example of list of label
But, when you want to use another model(ex. efficientdet), you need another annotation format! :disappointed_relieved:
Yolo-mark
outputs, but also OpenLabeling
outputs!You can make same environment with anaconda environment.
conda create -n Yolo-to-COCO python=3.8
conda activate Yolo-to-COCO
pip install numpy
pip install opencv-python
pip install imagesize
Just clone this repository.
git clone https://github.com/Taeyoung96/Yolo-to-COCO-format-converter.git
cd Yolo-to-COCO-format-converter
When you have your own Yolo annotation format, just change a little bit!
classes
with your own dataset.In main.py
, there is a code that declare the classes. You will change this with your obj.names
.
Next, follow step 2 if you have your annotations in separate text files, one for each image. Alternatively, follow step 3 if you wish to work from YOLO annotations which are concatenated into a single file.
Use this approach if your training data file structure looks like this:
dataset_root_dir/ Photo_00001.jpg Photo_00001.txt Photo_00002.jpg Photo_00003.txt
You don't need to specify yolo-subdir
argument.
python main.py --path <Absolute path to dataset_root_dir> --output <Name of the json file>
python main.py --path /home/taeyoungkim/Desktop/Yolo-to-COCO-format-converter/tutorial/ --output train
Use this approach if your annotations are in nested a level below the image files like this:
dataset_root_dir/ YOLO_darknet/ Photo_00001.txt Photo_00002.txt Photo_00001.jpg Photo_00002.jpg
Command to use:
python main.py --yolo-subdir --path <Absolute path to dataset_root_dir> --output <Name of the json file>
python main.py --yolo-subdir --box2seg --path <Absolute path to dataset_root_dir> --output <Name of the json file>
The arg --box2seg
initializes segmentation mask polygons that have box shapes.
This is useful for when changing your modeling from object detection to image segmentation.
These masks can then be reshaped using software such as the interface provided by makesense.ai
train.txt
.Make sure that it points to the absolute path to the folder where the image and text files are located.
You can easily change the path with Text Editor
(Ubuntu 18.04) or NotePad
(Window 10).
path_replacer.py
If you want to quickly create a train.txt file in Ubuntu, you can use path_replacer.py.
Works with 2 simple arguments.
path_txt: File path of the 'txt' file you want to create.
When you want to use
python path_replacer.py --path_image_folder <File path where the images are located> --path_txt <File path of the 'txt' file you want to create>
python path_replacer.py --path_image_folder /home/taeyoungkim/Desktop/Yolo-to-COCO-format-converter/tutorial/train --path_txt /home/taeyoungkim/Desktop/Yolo-to-COCO-format-converter/tutorial/train.txt
You need to provide 2 argments(essential) & 3 argments(optional).
essential
optional
When you want to make json file,
python main.py --path <Absolute Path of train.txt> --output <Name of the json file>
python main.py --path /home/taeyoungkim/Desktop/Yolo-to-COCO-format-converter/tutorial/train.txt --output train
Or when you want to check the bounding boxes,
python main.py --path <Absolute Path of train.txt> --output <Name of the json file> --debug
python main.py --path /home/taeyoungkim/Desktop/Yolo-to-COCO-format-converter/tutorial/train.txt --output train --debug
If you want to read json files more clearly, you should use JQ
!
cd output
jq . train.json > train_jq.json
Result of Json file
On debug mode, you can check bounding boxes
On debug mode, you can check annotation information on terminal
Copyright (c) 2021 Tae Young Kim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.