Open debpalash opened 1 year ago
The primary problem lies in exporting the COCO format, which requires the use of polygon labels. If you only have brush labels, this method will not function properly. I got a special case where I started manually with polygons and continued with the SAM ml backend integration. Therefore I've got two kinds of labels (brush and polygons) and the export breaks. It would be cool to have something working.
I found this online:
import json
import numpy as np
from pycocotools import mask
from skimage import measure
ground_truth_binary_mask = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.uint8)
fortran_ground_truth_binary_mask = np.asfortranarray(ground_truth_binary_mask)
encoded_ground_truth = mask.encode(fortran_ground_truth_binary_mask)
ground_truth_area = mask.area(encoded_ground_truth)
ground_truth_bounding_box = mask.toBbox(encoded_ground_truth)
contours = measure.find_contours(ground_truth_binary_mask, 0.5)
annotation = {
"segmentation": [],
"area": ground_truth_area.tolist(),
"iscrowd": 0,
"image_id": 123,
"bbox": ground_truth_bounding_box.tolist(),
"category_id": 1,
"id": 1
}
for contour in contours:
contour = np.flip(contour, axis=1)
segmentation = contour.ravel().tolist()
annotation["segmentation"].append(segmentation)
print(json.dumps(annotation, indent=4))
I don't know if you solved it or not, I had the same problem :(
Thank you for sharing, I actually integrated SAM to labelstudio manually
Is your feature request related to a problem? Please describe. CoCo and other export features are missing when a project created with sam according to label_studio-ml-backend/examples/segment_anything_model
Describe the solution you'd like To be able to export the instance segment annotations for yolov8
Describe alternatives you've considered converting json but it doesn't support segmentation on export popup
Additional context Project Label Setup