commit
20110cbcfa
51
README.md
51
README.md
|
@ -1,20 +1,20 @@
|
|||
**Forked from [rooneysh/Labelme2YOLO](https://github.com/rooneysh/Labelme2YOLO)**
|
||||
|
||||
# Labelme2YOLO
|
||||
|
||||
**Forked from [rooneysh/Labelme2YOLO](https://github.com/rooneysh/Labelme2YOLO)**
|
||||
|
||||
[](https://pypi.org/project/labelme2yolo)
|
||||

|
||||
[](https://pypi.org/project/labelme2yolo)
|
||||
[](https://www.codacy.com/gh/GreatV/labelme2yolo/dashboard?utm_source=github.com&utm_medium=referral&utm_content=GreatV/labelme2yolo&utm_campaign=Badge_Grade)
|
||||
[](https://www.codacy.com/gh/GreatV/labelme2yolo/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=GreatV/labelme2yolo\&utm_campaign=Badge_Grade)
|
||||
|
||||
Help converting LabelMe Annotation Tool JSON format to YOLO text file format.
|
||||
If you've already marked your segmentation dataset by LabelMe, it's easy to use this tool to help converting to YOLO format dataset.
|
||||
|
||||
---------
|
||||
|
||||
## New
|
||||
- export data as yolo polygon annotation (for YOLOv5 v7.0 segmentation)
|
||||
- Now you can choose the output format of the label text. The available options are `plygon` and `bbox`.
|
||||
|
||||
* export data as yolo polygon annotation (for YOLOv5 v7.0 segmentation)
|
||||
* Now you can choose the output format of the label text. The available options are `plygon` and `bbox`.
|
||||
|
||||
## Installation
|
||||
|
||||
```console
|
||||
|
@ -22,24 +22,29 @@ pip install labelme2yolo
|
|||
```
|
||||
|
||||
## Parameters Explain
|
||||
**--json_dir** LabelMe JSON files folder path.
|
||||
|
||||
**--val_size (Optional)** Validation dataset size, for example 0.2 means 20% for validation.
|
||||
**--json\_dir** LabelMe JSON files folder path.
|
||||
|
||||
**--test_size (Optional)** Test dataset size, for example 0.2 means 20% for Test.
|
||||
**--val\_size (Optional)** Validation dataset size, for example 0.2 means 20% for validation.
|
||||
|
||||
**--json_name (Optional)** Convert single LabelMe JSON file.
|
||||
**--test\_size (Optional)** Test dataset size, for example 0.2 means 20% for Test.
|
||||
|
||||
**--output_format (Optional)** The output format of label.
|
||||
**--json\_name (Optional)** Convert single LabelMe JSON file.
|
||||
|
||||
**--output\_format (Optional)** The output format of label.
|
||||
|
||||
## How to Use
|
||||
|
||||
### 1. Convert JSON files, split training, validation and test dataset by --val_size and --test_size
|
||||
Put all LabelMe JSON files under **labelme_json_dir**, and run this python command.
|
||||
### 1. Convert JSON files, split training, validation and test dataset by --val\_size and --test\_size
|
||||
|
||||
Put all LabelMe JSON files under **labelme\_json\_dir**, and run this python command.
|
||||
|
||||
```bash
|
||||
labelme2yolo --json_dir /path/to/labelme_json_dir/ --val_size 0.15 --test_size 0.15
|
||||
```
|
||||
|
||||
Script would generate YOLO format dataset labels and images under different folders, for example,
|
||||
|
||||
```bash
|
||||
/path/to/labelme_json_dir/YOLODataset/labels/train/
|
||||
/path/to/labelme_json_dir/YOLODataset/labels/test/
|
||||
|
@ -52,18 +57,24 @@ Script would generate YOLO format dataset labels and images under different fold
|
|||
```
|
||||
|
||||
### 2. Convert JSON files, split training and validation dataset by folder
|
||||
If you already split train dataset and validation dataset for LabelMe by yourself, please put these folder under labelme_json_dir, for example,
|
||||
|
||||
If you already split train dataset and validation dataset for LabelMe by yourself, please put these folder under labelme\_json\_dir, for example,
|
||||
|
||||
```bash
|
||||
/path/to/labelme_json_dir/train/
|
||||
/path/to/labelme_json_dir/val/
|
||||
```
|
||||
Put all LabelMe JSON files under **labelme_json_dir**.
|
||||
|
||||
Put all LabelMe JSON files under **labelme\_json\_dir**.
|
||||
Script would read train and validation dataset by folder.
|
||||
Run this python command.
|
||||
|
||||
```bash
|
||||
labelme2yolo --json_dir /path/to/labelme_json_dir/
|
||||
```
|
||||
|
||||
Script would generate YOLO format dataset labels and images under different folders, for example,
|
||||
|
||||
```bash
|
||||
/path/to/labelme_json_dir/YOLODataset/labels/train/
|
||||
/path/to/labelme_json_dir/YOLODataset/labels/val/
|
||||
|
@ -74,11 +85,15 @@ Script would generate YOLO format dataset labels and images under different fold
|
|||
```
|
||||
|
||||
### 3. Convert single JSON file
|
||||
Put LabelMe JSON file under **labelme_json_dir**. , and run this python command.
|
||||
|
||||
Put LabelMe JSON file under **labelme\_json\_dir**. , and run this python command.
|
||||
|
||||
```bash
|
||||
labelme2yolo --json_dir /path/to/labelme_json_dir/ --json_name 2.json
|
||||
```
|
||||
Script would generate YOLO format text label and image under **labelme_json_dir**, for example,
|
||||
|
||||
Script would generate YOLO format text label and image under **labelme\_json\_dir**, for example,
|
||||
|
||||
```bash
|
||||
/path/to/labelme_json_dir/2.text
|
||||
/path/to/labelme_json_dir/2.png
|
||||
|
|
|
@ -93,15 +93,15 @@ def get_label_id_map(json_dir):
|
|||
return OrderedDict([(label, label_id) for label_id, label in enumerate(label_set)])
|
||||
|
||||
|
||||
def extend_point_list(point_list, format="polygon"):
|
||||
def extend_point_list(point_list, out_format="polygon"):
|
||||
xmin = min([float(point) for point in point_list[::2]])
|
||||
xmax = max([float(point) for point in point_list[::2]])
|
||||
ymin = min([float(point) for point in point_list[1::2]])
|
||||
ymax = max([float(point) for point in point_list[1::2]])
|
||||
|
||||
if (format == "polygon"):
|
||||
if (out_format == "polygon"):
|
||||
return np.array([xmin, ymin, xmax, ymin, xmax, ymax, xmin, ymax])
|
||||
if (format == "bbox"):
|
||||
if (out_format == "bbox"):
|
||||
return np.array([xmin, ymin, xmax - xmin, ymax - ymin])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue