<aside> <img src="/icons/warning_gray.svg" alt="/icons/warning_gray.svg" width="40px" /> The following guide is created on macOS so you might need to adapt a few of them on your platform. Feel free to ask me questions via email.
</aside>
<aside> <img src="/icons/light-bulb_gray.svg" alt="/icons/light-bulb_gray.svg" width="40px" /> Follow previous guide (Export a Labelme JSON file to PNG and etc. ) to export files or download them from below:
<aside> <img src="/icons/document_gray.svg" alt="/icons/document_gray.svg" width="40px" /> The exported files that are zipped (to open please double-click to extract):
</aside>
</aside>
Make sure you have dogs_edited_json
directory.
$ ls dogs_edited_json
img.png label.png label_names.txt label_viz.png
Install required software following Install labelme Python package
Create a Python file load_exported_files.py
:
import numpy as np
import PIL.Image
import matplotlib.pyplot as plt
# load exported files
image = np.asarray(PIL.Image.open("dogs_edited_json/img.png"))
label = np.asarray(PIL.Image.open("dogs_edited_json/label.png"))
with open("dogs_edited_json/label_names.txt", "r") as f:
label_names = f.read().splitlines()
# extract masks from label
masks = {}
for label_id, label_name in enumerate(label_names):
mask = label == label_id
masks[(label_id, label_name)] = mask
# print stats
print("image:", image.shape, image.dtype)
print("label:", label.shape, label.dtype)
print("label_names:", label_names)
# visualize
rows = 2
columns = max(2, len(label_names))
#
plt.subplot(rows, columns, 1)
plt.title("image")
plt.imshow(image)
#
plt.subplot(rows, columns, 2)
plt.title("label")
plt.imshow(label)
#
plt.subplot(rows, columns, 3)
plt.title("label overlaid")
plt.imshow(image)
plt.imshow(label, alpha=0.5)
#
for (label_id, label_name), mask in masks.items():
plt.subplot(rows, columns, 4 + label_id)
plt.title(f"{label_id}:{label_name}")
plt.imshow(mask, cmap="gray")
#
plt.tight_layout()
plt.show()
<aside> <img src="/icons/document_gray.svg" alt="/icons/document_gray.svg" width="40px" /> The Python file:
</aside>
That’s all! Now you’re ready to start building your own dataset using Labelme.