DnaRnaProteins/cell_seg_labeled
Updated โข 39
How to use DnaRnaProteins/sam2-cells-seg with sam2:
# Use SAM2 with images
import torch
from sam2.sam2_image_predictor import SAM2ImagePredictor
predictor = SAM2ImagePredictor.from_pretrained(DnaRnaProteins/sam2-cells-seg)
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>) # Use SAM2 with videos
import torch
from sam2.sam2_video_predictor import SAM2VideoPredictor
predictor = SAM2VideoPredictor.from_pretrained(DnaRnaProteins/sam2-cells-seg)
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
state = predictor.init_state(<your_video>)
# add new prompts and instantly get the output on the same frame
frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>):
# propagate the prompts to get masklets throughout the video
for frame_idx, object_ids, masks in predictor.propagate_in_video(state):
...Fine-tuned SAM2-tiny for instance segmentation of cells in fluorescence microscopy images. Part of the biomech-inference-serving pipeline (internal research project).
| Base model | facebook/sam2.1-hiera-tiny |
| Training data | DnaRnaProteins/cell_seg_labeled |
| Fine-tuning | Full decoder fine-tune |
| Framework | sam2 |
import numpy as np, torch
from PIL import Image
from sam2.sam2_image_predictor import SAM2ImagePredictor
predictor = SAM2ImagePredictor.from_pretrained("DnaRnaProteins/sam2-cells-seg")
image = np.array(Image.open("cell_image.png").convert("RGB"))
predictor.set_image(image)
with torch.inference_mode():
masks, scores, _ = predictor.predict(
point_coords=np.array([[128, 256]]), # [x, y] prompt point
point_labels=np.array([1]),
multimask_output=True,
)
# masks: (N, H, W) bool array
# scores: (N,) float confidence per mask
import base64, modal
segment = modal.Function.from_name("biomech-inference-serving", "segment")
with open("cell_image.png", "rb") as f:
b64 = base64.b64encode(f.read()).decode()
result = segment.remote(b64)
# {"masks": [[...]], "scores": [0.94, ...]}
Base model
facebook/sam2.1-hiera-tiny