↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
I am writing an article on the assumption that I have the following knowledge
It's an app like this
When you open labelme, the following window will open. (The image is a screenshot of the google search screen. It's hard to understand ...)
While expanding, draw a line at the point. It's very easy to zoom in and out.
I think it's about 1min with this proper feeling. Pretty easy to use. ..
Save the JSON from SAVE on the left. You can get data like this!
{
"version": "4.5.6",
"flags": {},
"shapes": [
{
"label": "dog",
"points": [
[
104.36893203883496,
66.99029126213593
],
[
93.44660194174757,
71.35922330097087
],
Omitted here
[
112.13592233009709,
74.27184466019418
],
[
107.28155339805825,
73.30097087378641
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}
],
"imagePath": "Screenshot 2020-09-14 141400.png ",
"imageData": "abridgement",
"imageHeight": 405,
"imageWidth": 535
}
Caution! Since this JSON point is a polygon point, it cannot be used as a mask as it is. .. So we need to convert this point to a mask.
At first I was thinking of implementing it myself (it's a hassle), but there was a function for it (that's right). labelme has a module called shape.py in the utils folder, and you can convert from JSON to MASK by using the shape_to_mask function.
However, I have to implement it subtly, so I will post the sample code.
import json
with open(path, "r",encoding="utf-8") as f:
dj = json.load(f)
# dj['shapes'][0]Is for one label this time.
mask = shape_to_mask((dj['imageHeight'],dj['imageWidth']), dj['shapes'][0]['points'], shape_type=None,line_width=1, point_size=1)
mask_img = mask.astype(np.int)#boolean to 0,Convert to 1
#I'm using anaconda
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(mask_img)
I was able to label it well. At this level, it takes about 2-3 minutes from opening the image to saving it, isn't it?
Please let me know if you have any recommended labeling tools other than label me. I wonder if some people have implemented it on their own.
Recommended Posts