Downloads · 30 days
37
3% of all-time downloads
Xenova/clipseg-rd64
clipseg-rd64 is a image segmentation model from Xenova. Use it for the image segmentation task on the model card, and read the license before you ship it in a product. It is set up for transformers.js.
https://huggingface.co/CIDAS/clipseg-rd64 with ONNX weights to be compatible with Transformers.js.
Downloads · 30 days
37
3% of all-time downloads
All-time downloads
1.1K
Public
Repo size
1.6 GB
Likes
1
Public
Click a slice to open those files.
.onnx957 MB · 100%
From the Hugging Face model README
https://huggingface.co/CIDAS/clipseg-rd64 with ONNX weights to be compatible with Transformers.js.
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @xenova/transformers
Example: Perform zero-shot image segmentation with a CLIPSegForImageSegmentation model.
import { AutoTokenizer, AutoProcessor, CLIPSegForImageSegmentation, RawImage } from '@xenova/transformers';
// Load tokenizer, processor, and model
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/clipseg-rd64');
const processor = await AutoProcessor.from_pretrained('Xenova/clipseg-rd64');
const model = await CLIPSegForImageSegmentation.from_pretrained('Xenova/clipseg-rd64');
// Run tokenization
const texts = ['a glass', 'something to fill', 'wood', 'a jar'];
const text_inputs = tokenizer(texts, { padding: true, truncation: true });
// Read image and run processor
const image = await RawImage.read('https://github.com/timojl/clipseg/blob/master/example_image.jpg?raw=true');
const image_inputs = await processor(image);
// Run model with both text and pixel inputs
const { logits } = await model({ ...text_inputs, ...image_inputs });
// logits: Tensor {
// dims: [4, 352, 352],
// type: 'float32',
// data: Float32Array(495616)[ ... ],
// size: 495616
// }
You can visualize the predictions as follows:
// Visualize images
const preds = logits
.unsqueeze_(1)
.sigmoid_()
.mul_(255)
.round_()
.to('uint8');
for (let i = 0; i < preds.dims[0]; ++i) {
const img = RawImage.fromTensor(preds[i]);
img.save(`prediction_${i}.png`);
}
| Original | "a glass" | "something to fill" | "wood" | "a jar" |
|---|---|---|---|---|
![]() | ![]() | ![]() | ![]() | ![]() |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using 🤗 Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).