diff --git a/README.md b/README.md index 30084b2..db92fc1 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,12 @@ ## Dataset types +`PASCAL VOC`: Pascal voc dataset have a xml file for each image. + +`YOLO`: YOLO dataset have a txt file for each image. + +`COCO`: COCO dataset have a json file for each image. + ## Current support format Currently, the following formats are supported: @@ -16,12 +22,15 @@ Currently, the following formats are supported: ## Upcoming support format -| from | to | Issue/PR(if any) | -| :--------: | :--------------------: | ---------------- | -| PASCAL VOC | COCO (JSON files) | No | -| COCO | PASCAL VOC (XML files) | No | -| COCO | YOLO (TXT files) | No | -| YOLO | COCO (JSON files) | No | +| from | to | Issue/PR(if any) | +| :--------: | :-----------------------: | ---------------- | +| PASCAL VOC | COCO (JSON files) | No | +| PASCAL VOC | TFRecord (TFRecord files) | No | +| COCO | PASCAL VOC (XML files) | No | +| COCO | YOLO (TXT files) | No | +| COCO | TFRecord (TFRecord files) | No | +| YOLO | COCO (JSON files) | No | +| YOLO | TFRecord (TFRecord files) | No | ## Installation @@ -61,7 +70,7 @@ python convert.py --input-folder ./data/pascal_voc \ ## Contributing -create an issue/PR if any format is missing.Open-source contribution is welcome.check the [contributing guide](/CONTRIBUTING.md) for details. +create an issue/PR if any format is missing.Open-source contribution is welcome.check the [contributing guide](/CONTRIBUTING.md) for details. ## Reference diff --git a/output/README.md b/output/README.md deleted file mode 100644 index e64b2da..0000000 --- a/output/README.md +++ /dev/null @@ -1 +0,0 @@ -# Output folder after running the script diff --git a/requirements.txt b/requirements.txt index 1dbed7b..a917f02 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/utils.py b/src/utils.py index 5d4a36d..0e0cda8 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,15 +1,30 @@ import os -from PIL import Image -from glob import glob -from xml.etree import ElementTree as ET import shutil +from glob import glob +from PIL import Image +from pathlib import Path from datetime import datetime -from path import Path +from xml.etree import ElementTree as ET + class Convertor: ''' Convertor class is a class for converting images and annotations from one format to another. + + Usage: + # voc to yolo + convertor = Convertor('data/VOC2007', 'outout/VOC2007_yolo', 'voc', 'yolo') + convertor.voc2yolo() + + # voc to coco + convertor = Convertor('data/VOC2007', 'outout/VOC2007_coco', 'voc', 'coco') + convertor.voc2coco() + + # yolo to voc + convertor = Convertor('data/yolo', 'outout/VOC2007', 'yolo', 'voc') + convertor.yolo2voc() + Parameters ---------- @@ -30,13 +45,40 @@ class Convertor: yolo2voc() Convert Yolo5 format to Pascal VOC format. + yolo2coco() + Convert Yolo5 format to COCO format. + + coco2yolo() + Convert COCO format to Yolo5 format. + + voc2coco() + Convert Pascal VOC format to COCO format. + + coco2voc() + Convert COCO format to Pascal VOC format. + + pascal2tfrecord() + Convert Pascal VOC format to TFRecord format. + + coco2tfrecord() + Convert COCO format to TFRecord format. + + yolo2tfrecord() + Convert Yolo5 format to TFRecord format. + + # Pascal Voc - XML # Pascal VOC format is a XML file format for images and annotations. + # Yolo5 - TXT # Yolo5 format is a text file format for images and annotations. + # COCO - JSON # COCO format is a JSON file format for images and annotations. + # TFRecord - TFRecord + # TFRecord format is a TFRecord file format for images and annotations. + ''' def __init__(self, input_folder, outout_folder, input_format, output_format): root_dit = Path(__file__).parent.parent # root directory @@ -88,7 +130,7 @@ def voc2yolo(self): f.write(label + ' ' + str(x) + ' ' + str(y) + ' ' + str(w) + ' ' + str(h) + '\n') else: - print('Not support') + print('Conversion not supported yet, please check https://github.com/codePerfectPlus/dataset-convertor and create an issue.') def yolo2voc(self): ''' yolo txt format to pascal voc xml format ''' @@ -151,7 +193,7 @@ def yolo2voc(self): tree = ET.ElementTree(root) tree.write(os.path.join(self.output_annotation_folder, image_file_name[:-4] + '.xml')) else: - print('Not support') + print('Conversion not supported yet, please check https://github.com/codePerfectPlus/dataset-convertor and create an issue.') def yolo2coco(self): ''' yolo txt format to coco json format ''' @@ -168,3 +210,16 @@ def voc2coco(self): def coco2voc(self): ''' coco json format to voc xml format ''' pass + + def coco2tfrecord(self): + ''' coco json format to tfrecord format ''' + pass + + def yolo2tfrecord(self): + ''' yolo txt format to tfrecord format ''' + pass + + def voc2tfrecord(self): + ''' voc xml format to tfrecord format ''' + pass + \ No newline at end of file