facebookresearch / segment-anything

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
46.56k stars 5.52k forks source link

Web version support for labeling #65

Open AmartyaCSB opened 1 year ago

AmartyaCSB commented 1 year ago

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?

zhongwei commented 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)
lujiazho commented 1 year ago

Here is a simple implementation of web-based mask-drawer if interested: https://github.com/lujiazho/SegDrawer

Kingfish404 commented 1 year ago

Yet another SAM web UI https://github.com/kingfish404/segment-anything-webui

DuinoDu commented 1 year ago

CVAT also supports SAM, FYI.