Skip to content

Commit 20110cb

Browse files
authored
Merge pull request #13 from GreatV/markdown_lint
markdown lint
2 parents c008d6c + 4af6173 commit 20110cb

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

README.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
1-
**Forked from [rooneysh/Labelme2YOLO](https://github.com/rooneysh/Labelme2YOLO)**
2-
31
# Labelme2YOLO
42

3+
**Forked from [rooneysh/Labelme2YOLO](https://github.com/rooneysh/Labelme2YOLO)**
4+
55
[![PyPI - Version](https://img.shields.io/pypi/v/labelme2yolo.svg)](https://pypi.org/project/labelme2yolo)
66
![PyPI - Downloads](https://img.shields.io/pypi/dm/labelme2yolo?style=flat)
77
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/labelme2yolo.svg)](https://pypi.org/project/labelme2yolo)
8-
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/12122fe86f8643c4aa5667c20d528f61)](https://www.codacy.com/gh/GreatV/labelme2yolo/dashboard?utm_source=github.com&utm_medium=referral&utm_content=GreatV/labelme2yolo&utm_campaign=Badge_Grade)
8+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/12122fe86f8643c4aa5667c20d528f61)](https://www.codacy.com/gh/GreatV/labelme2yolo/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=GreatV/labelme2yolo\&utm_campaign=Badge_Grade)
99

10-
Help converting LabelMe Annotation Tool JSON format to YOLO text file format.
10+
Help converting LabelMe Annotation Tool JSON format to YOLO text file format.
1111
If you've already marked your segmentation dataset by LabelMe, it's easy to use this tool to help converting to YOLO format dataset.
1212

13-
---------
14-
1513
## New
16-
- export data as yolo polygon annotation (for YOLOv5 v7.0 segmentation)
17-
- Now you can choose the output format of the label text. The available options are `plygon` and `bbox`.
14+
15+
* export data as yolo polygon annotation (for YOLOv5 v7.0 segmentation)
16+
* Now you can choose the output format of the label text. The available options are `plygon` and `bbox`.
17+
1818
## Installation
1919

2020
```console
2121
pip install labelme2yolo
2222
```
2323

2424
## Parameters Explain
25-
**--json_dir** LabelMe JSON files folder path.
2625

27-
**--val_size (Optional)** Validation dataset size, for example 0.2 means 20% for validation.
26+
**--json\_dir** LabelMe JSON files folder path.
27+
28+
**--val\_size (Optional)** Validation dataset size, for example 0.2 means 20% for validation.
2829

29-
**--test_size (Optional)** Test dataset size, for example 0.2 means 20% for Test.
30+
**--test\_size (Optional)** Test dataset size, for example 0.2 means 20% for Test.
3031

31-
**--json_name (Optional)** Convert single LabelMe JSON file.
32+
**--json\_name (Optional)** Convert single LabelMe JSON file.
3233

33-
**--output_format (Optional)** The output format of label.
34+
**--output\_format (Optional)** The output format of label.
3435

3536
## How to Use
3637

37-
### 1. Convert JSON files, split training, validation and test dataset by --val_size and --test_size
38-
Put all LabelMe JSON files under **labelme_json_dir**, and run this python command.
38+
### 1. Convert JSON files, split training, validation and test dataset by --val\_size and --test\_size
39+
40+
Put all LabelMe JSON files under **labelme\_json\_dir**, and run this python command.
41+
3942
```bash
4043
labelme2yolo --json_dir /path/to/labelme_json_dir/ --val_size 0.15 --test_size 0.15
4144
```
45+
4246
Script would generate YOLO format dataset labels and images under different folders, for example,
47+
4348
```bash
4449
/path/to/labelme_json_dir/YOLODataset/labels/train/
4550
/path/to/labelme_json_dir/YOLODataset/labels/test/
@@ -52,18 +57,24 @@ Script would generate YOLO format dataset labels and images under different fold
5257
```
5358

5459
### 2. Convert JSON files, split training and validation dataset by folder
55-
If you already split train dataset and validation dataset for LabelMe by yourself, please put these folder under labelme_json_dir, for example,
60+
61+
If you already split train dataset and validation dataset for LabelMe by yourself, please put these folder under labelme\_json\_dir, for example,
62+
5663
```bash
5764
/path/to/labelme_json_dir/train/
5865
/path/to/labelme_json_dir/val/
5966
```
60-
Put all LabelMe JSON files under **labelme_json_dir**.
67+
68+
Put all LabelMe JSON files under **labelme\_json\_dir**.
6169
Script would read train and validation dataset by folder.
6270
Run this python command.
71+
6372
```bash
6473
labelme2yolo --json_dir /path/to/labelme_json_dir/
6574
```
75+
6676
Script would generate YOLO format dataset labels and images under different folders, for example,
77+
6778
```bash
6879
/path/to/labelme_json_dir/YOLODataset/labels/train/
6980
/path/to/labelme_json_dir/YOLODataset/labels/val/
@@ -74,11 +85,15 @@ Script would generate YOLO format dataset labels and images under different fold
7485
```
7586

7687
### 3. Convert single JSON file
77-
Put LabelMe JSON file under **labelme_json_dir**. , and run this python command.
88+
89+
Put LabelMe JSON file under **labelme\_json\_dir**. , and run this python command.
90+
7891
```bash
7992
labelme2yolo --json_dir /path/to/labelme_json_dir/ --json_name 2.json
8093
```
81-
Script would generate YOLO format text label and image under **labelme_json_dir**, for example,
94+
95+
Script would generate YOLO format text label and image under **labelme\_json\_dir**, for example,
96+
8297
```bash
8398
/path/to/labelme_json_dir/2.text
8499
/path/to/labelme_json_dir/2.png

src/labelme2yolo/l2y.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ def get_label_id_map(json_dir):
9393
return OrderedDict([(label, label_id) for label_id, label in enumerate(label_set)])
9494

9595

96-
def extend_point_list(point_list, format="polygon"):
96+
def extend_point_list(point_list, out_format="polygon"):
9797
xmin = min([float(point) for point in point_list[::2]])
9898
xmax = max([float(point) for point in point_list[::2]])
9999
ymin = min([float(point) for point in point_list[1::2]])
100100
ymax = max([float(point) for point in point_list[1::2]])
101101

102-
if (format == "polygon"):
102+
if (out_format == "polygon"):
103103
return np.array([xmin, ymin, xmax, ymin, xmax, ymax, xmin, ymax])
104-
if (format == "bbox"):
104+
if (out_format == "bbox"):
105105
return np.array([xmin, ymin, xmax - xmin, ymax - ymin])
106106

107107

0 commit comments

Comments
 (0)