Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony607 committed Jul 27, 2019
1 parent 56257e0 commit 8dde052
Show file tree
Hide file tree
Showing 39 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -2,4 +2,4 @@
*.ipynb_checkpoints
__pycache__
.vscode/
coco.json
trainval.json
4 changes: 2 additions & 2 deletions 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`

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
20 changes: 10 additions & 10 deletions labelme2coco.py
Expand Up @@ -2,7 +2,6 @@
import argparse
import json

# import cv2
from labelme import utils
import numpy as np
import glob
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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)

0 comments on commit 8dde052

Please sign in to comment.