Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Python 3.8 or later with all [requirements.txt](https://github.com/ultralytics/J
$ pip install -r requirements.txt
```

# How to use

```bash
$ python general_json2yolo.py -source coco -json_dir annotations/
```

# Citation

[![DOI](https://zenodo.org/badge/186122711.svg)](https://zenodo.org/badge/latestdoi/186122711)
Expand Down
15 changes: 11 additions & 4 deletions general_json2yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PIL import Image

from utils import *
import argparse


# Convert INFOLKS JSON file into YOLO-format labels ----------------------------
Expand Down Expand Up @@ -282,17 +283,23 @@ def convert_coco_json(json_dir='../coco/annotations/', use_segments=False):

# Write
if box[2] > 0 and box[3] > 0: # if w > 0 and h > 0
line = coco80[x['category_id'] - 1], *(s if use_segments else box) # cls, box or segments
line = x['category_id'] - 1, *(s if use_segments else box) # cls, box or segments
with open((fn / f).with_suffix('.txt'), 'a') as file:
file.write(('%g ' * len(line)).rstrip() % line + '\n')


if __name__ == '__main__':
source = 'coco'

parser = argparse.ArgumentParser()
parser.add_argument('-json_dir', action='store', help='please include the full path of the folder with bounding boxes (.json)', type=str)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use relative paths?

parser.add_argument('-source', action='store', help='define the format to convert to yolo (coco,infolks,vott,ath)', type=str,default="coco")
args = parser.parse_args()
json_dir=args.json_dir
source=args.source

if source == 'coco':
convert_coco_json('../../Downloads/coco/annotations/')

convert_coco_json(json_dir)
elif source == 'infolks': # Infolks https://infolks.info/
convert_infolks_json(name='out',
files='../data/sm4/json/*.json',
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Pillow
pyYAML
requests
tqdm
argparse