Skip to content

Python script to generate annotation for CreateML in a JSON format.

Notifications You must be signed in to change notification settings

ESbros/CreateML_Annotations_JSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

Generate Annotations JSON Format for CreateML with Python

Python script which generates annotations in JSON format required for training object detection models using CreateML.

CreateML requires a list of dictionaries with information about the selected bounding boxes: center and size (height and width) of the bounding box.

annotations

Code Description

The following code shows how to draw bounding boxes using matplotlib library. It iterates over the images of a folder and draws bounding boxes to get the center coodinates, heitgh and width of the bounding box.

Detailed description on: https://medium.com/@eriksols/generate-annotations-json-format-for-createml-apple-with-python-90fc848cd439?postPublishedType=repub

Run Script

Pass the path to the images folder (image_folder = 'path_to_image_folder'). Each image must be named with the corresponding class in order to detect the label, example: 'dog_01.jpg'.

folder_exm

Run generate_json.py script

Code will iterate over all the images contained on the images folder.

Now, you must draw the bounding box over the interest object. Once you are confident about the drawn bounding box, press "q" to generate and store the corresponding dictionary and continue the process with the next image.

bb

A list containing the dictionaries of all images will be generated.

dict

Finally a JSON file will be generated.

json_file

Open and Iterate JSON file

Run open_json_file.py

This script opens and iterates over the list containing the image dictionaries. This script also shows how to access the the list elements and the corresponding dictionaries.

It prints: List length (number of contained dictionaries) Image dictionary Label dictionary Coordinates dictionary

res

That's all! :D

About

Python script to generate annotation for CreateML in a JSON format.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages