Gaurav C

cggaurav
ยท

AI & ML interests

None yet

Recent Activity

Organizations

None yet

cggaurav's activity

New activity in SJ-Ray/Re-Punctuate 9 months ago
New activity in 1-800-BAD-CODE/punct_cap_seg_47_language 9 months ago

What is <unk>?

#1 opened 9 months ago by cggaurav
replied to Xenova's post 10 months ago
Reacted to Xenova's post with โค๏ธ 10 months ago
view post
Post
Last week, we released ๐Ÿค— Transformers.js v2.14, which added support for SAM (Segment Anything Model).

This means you can now generate high-quality segmentation masks for objects in a scene, directly in your browser! ๐Ÿคฏ

Demo (+ source code): Xenova/segment-anything-web
Model: Xenova/slimsam-77-uniform

But how does this differ from Meta's original demo? ๐Ÿค” Didn't that also run in-browser?

Well, in their demo, the image embeddings are computed server-side, then sent to the client for decoding. Trying to do this all client-side would be completely impractical: taking minutes per image! ๐Ÿ˜ตโ€๐Ÿ’ซ

That's where SlimSAM comes to the rescue! SlimSAM is a novel SAM compression method, able to shrink the model over 100x (637M โ†’ 5.5M params), while still achieving remarkable results!

The best part? You can get started in a few lines of JavaScript code, thanks to Transformers.js! ๐Ÿ”ฅ

// npm i @xenova/transformers
import { SamModel, AutoProcessor, RawImage } from '@xenova/transformers';

// Load model and processor
const model = await SamModel.from_pretrained('Xenova/slimsam-77-uniform');
const processor = await AutoProcessor.from_pretrained('Xenova/slimsam-77-uniform');

// Prepare image and input points
const img_url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/corgi.jpg';
const raw_image = await RawImage.read(img_url);
const input_points = [[[340, 250]]];

// Process inputs and perform mask generation
const inputs = await processor(raw_image, input_points);
const outputs = await model(inputs);

// Post-process masks
const masks = await processor.post_process_masks(outputs.pred_masks, inputs.original_sizes, inputs.reshaped_input_sizes);
console.log(masks);

// Visualize the mask
const image = RawImage.fromTensor(masks[0][0].mul(255));
image.save('mask.png');


I can't wait to see what you build with it! ๐Ÿค—
ยท