diff --git a/.gitignore b/.gitignore index 7893ef0..f7e4afc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ *.ipynb_checkpoints __pycache__ .vscode/ -coco.json +trainval.json diff --git a/README.md b/README.md index 5f8d20f..4238370 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# [How to create custom COCO data set for instance segmentation]() | DLology blog +# [How to create custom COCO data set for instance segmentation](https://www.dlology.com/blog/how-to-create-custom-coco-data-set-for-instance-segmentation/) | DLology blog ## Quick start Then you can run the `labelme2coco.py` script to generate a COCO data formatted JSON file for you. ``` -python labelme2coco.py labelme_images +python labelme2coco.py images ``` Then you can run the following Jupyter notebook to visualize the coco annotations. `COCO_Image_Viewer.ipynb` diff --git a/labelme_images/0.jpg b/images/0.jpg similarity index 100% rename from labelme_images/0.jpg rename to images/0.jpg diff --git a/labelme_images/0.json b/images/0.json similarity index 100% rename from labelme_images/0.json rename to images/0.json diff --git a/labelme_images/1.jpg b/images/1.jpg similarity index 100% rename from labelme_images/1.jpg rename to images/1.jpg diff --git a/labelme_images/1.json b/images/1.json similarity index 100% rename from labelme_images/1.json rename to images/1.json diff --git a/labelme_images/10.jpg b/images/10.jpg similarity index 100% rename from labelme_images/10.jpg rename to images/10.jpg diff --git a/labelme_images/10.json b/images/10.json similarity index 100% rename from labelme_images/10.json rename to images/10.json diff --git a/labelme_images/11.jpg b/images/11.jpg similarity index 100% rename from labelme_images/11.jpg rename to images/11.jpg diff --git a/labelme_images/11.json b/images/11.json similarity index 100% rename from labelme_images/11.json rename to images/11.json diff --git a/labelme_images/12.jpg b/images/12.jpg similarity index 100% rename from labelme_images/12.jpg rename to images/12.jpg diff --git a/labelme_images/12.json b/images/12.json similarity index 100% rename from labelme_images/12.json rename to images/12.json diff --git a/labelme_images/13.jpg b/images/13.jpg similarity index 100% rename from labelme_images/13.jpg rename to images/13.jpg diff --git a/labelme_images/13.json b/images/13.json similarity index 100% rename from labelme_images/13.json rename to images/13.json diff --git a/labelme_images/14.jpg b/images/14.jpg similarity index 100% rename from labelme_images/14.jpg rename to images/14.jpg diff --git a/labelme_images/14.json b/images/14.json similarity index 100% rename from labelme_images/14.json rename to images/14.json diff --git a/labelme_images/15.jpg b/images/15.jpg similarity index 100% rename from labelme_images/15.jpg rename to images/15.jpg diff --git a/labelme_images/15.json b/images/15.json similarity index 100% rename from labelme_images/15.json rename to images/15.json diff --git a/labelme_images/16.jpg b/images/16.jpg similarity index 100% rename from labelme_images/16.jpg rename to images/16.jpg diff --git a/labelme_images/16.json b/images/16.json similarity index 100% rename from labelme_images/16.json rename to images/16.json diff --git a/labelme_images/17.jpg b/images/17.jpg similarity index 100% rename from labelme_images/17.jpg rename to images/17.jpg diff --git a/labelme_images/17.json b/images/17.json similarity index 100% rename from labelme_images/17.json rename to images/17.json diff --git a/labelme_images/2.jpg b/images/2.jpg similarity index 100% rename from labelme_images/2.jpg rename to images/2.jpg diff --git a/labelme_images/2.json b/images/2.json similarity index 100% rename from labelme_images/2.json rename to images/2.json diff --git a/labelme_images/3.jpg b/images/3.jpg similarity index 100% rename from labelme_images/3.jpg rename to images/3.jpg diff --git a/labelme_images/3.json b/images/3.json similarity index 100% rename from labelme_images/3.json rename to images/3.json diff --git a/labelme_images/4.jpg b/images/4.jpg similarity index 100% rename from labelme_images/4.jpg rename to images/4.jpg diff --git a/labelme_images/4.json b/images/4.json similarity index 100% rename from labelme_images/4.json rename to images/4.json diff --git a/labelme_images/5.jpg b/images/5.jpg similarity index 100% rename from labelme_images/5.jpg rename to images/5.jpg diff --git a/labelme_images/5.json b/images/5.json similarity index 100% rename from labelme_images/5.json rename to images/5.json diff --git a/labelme_images/6.jpg b/images/6.jpg similarity index 100% rename from labelme_images/6.jpg rename to images/6.jpg diff --git a/labelme_images/6.json b/images/6.json similarity index 100% rename from labelme_images/6.json rename to images/6.json diff --git a/labelme_images/7.jpg b/images/7.jpg similarity index 100% rename from labelme_images/7.jpg rename to images/7.jpg diff --git a/labelme_images/7.json b/images/7.json similarity index 100% rename from labelme_images/7.json rename to images/7.json diff --git a/labelme_images/8.jpg b/images/8.jpg similarity index 100% rename from labelme_images/8.jpg rename to images/8.jpg diff --git a/labelme_images/8.json b/images/8.json similarity index 100% rename from labelme_images/8.json rename to images/8.json diff --git a/labelme_images/9.jpg b/images/9.jpg similarity index 100% rename from labelme_images/9.jpg rename to images/9.jpg diff --git a/labelme_images/9.json b/images/9.json similarity index 100% rename from labelme_images/9.json rename to images/9.json diff --git a/labelme2coco.py b/labelme2coco.py index 3039653..72b3922 100644 --- a/labelme2coco.py +++ b/labelme2coco.py @@ -2,7 +2,6 @@ import argparse import json -# import cv2 from labelme import utils import numpy as np import glob @@ -20,7 +19,6 @@ def __init__(self, labelme_json=[], save_json_path="./coco.json"): self.images = [] self.categories = [] self.annotations = [] - # self.data_coco = {} self.label = [] self.annID = 1 self.height = 0 @@ -36,7 +34,7 @@ def data_transfer(self): for shapes in data["shapes"]: label = shapes["label"].split("_") if label not in self.label: - self.categories.append(self.categorie(label)) + self.categories.append(self.category(label)) self.label.append(label) points = shapes["points"] self.annotations.append(self.annotation(points, label, num)) @@ -57,12 +55,12 @@ def image(self, data, num): return image - def categorie(self, label): - categorie = {} - categorie["supercategory"] = label[0] - categorie["id"] = len(self.label) + 1 - categorie["name"] = label[0] - return categorie + def category(self, label): + category = {} + category["supercategory"] = label[0] + category["id"] = len(self.label) + 1 + category["name"] = label[0] + return category def annotation(self, points, label, num): annotation = {} @@ -150,7 +148,9 @@ def save_json(self): help="Directory to labelme images and annotation json files.", type=str, ) - parser.add_argument("--output", help="Output json file path.", default="coco.json") + parser.add_argument( + "--output", help="Output json file path.", default="trainval.json" + ) args = parser.parse_args() labelme_json = glob.glob(os.path.join(args.labelme_images, "*.json")) labelme2coco(labelme_json, args.output)