Skip to content

Commit

Permalink
🎨 code refactoring and updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Dec 9, 2021
1 parent a71be8c commit 01433cb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion output/README.md

This file was deleted.

Binary file modified requirements.txt
Binary file not shown.
67 changes: 61 additions & 6 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -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
----------
Expand All @@ -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
Expand Down Expand Up @@ -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 '''
Expand Down Expand Up @@ -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 '''
Expand All @@ -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

0 comments on commit 01433cb

Please sign in to comment.