Open AmartyaCSB opened 1 year ago
import cv2, json
from segment_anything import SamAutomaticMaskGenerator, sam_model_registry
sam = sam_model_registry['vit_b'](checkpoint='sam_vit_b_01ec64.pth')
generator = SamAutomaticMaskGenerator(sam, output_mode='coco_rle')
image = cv2.imread('punch_out.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
masks = generator.generate(image)
with open('sample_segment.json', "w") as f:
json.dump(masks, f)
Here is a simple implementation of web-based mask-drawer if interested: https://github.com/lujiazho/SegDrawer
Yet another SAM web UI https://github.com/kingfish404/segment-anything-webui
CVAT also supports SAM, FYI.
Thanks for the fantastic research and the code. It is very beneficial as it supports zero shot segmentation
Can we use the pre-trained models for custom images? Researchers can also use this for labeling their images if we can use the web tool and perform labeling and create a JSON/COCO format file. Any ideas?