ONNX Model Zoo

Ahmed107/apple_MobileCLIP-S0

By Ahmed107 · ↓ 2 · ♥ 2 · Updated 2024-08-27

What's in this repo

This page lists the files in Ahmed107/apple_MobileCLIP-S0, including text_model.onnx, text_model_bnb4.onnx, text_model_fp16.onnx and more.

  • 14 ONNX models (.onnx files)
  • 21 files, including 14 .onnx, 4 .json, 1 .md
  • Last updated 2024-08-27

ONNX files

File Size Download
onnx/text_model.onnx — Download
onnx/text_model_bnb4.onnx — Download
onnx/text_model_fp16.onnx — Download
onnx/text_model_int8.onnx — Download
onnx/text_model_q4.onnx — Download
onnx/text_model_quantized.onnx — Download
onnx/text_model_uint8.onnx — Download
onnx/vision_model.onnx — Download
onnx/vision_model_bnb4.onnx — Download
onnx/vision_model_fp16.onnx — Download

Showing 10 of 14 .onnx files — see the full file list on the right.

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

https://github.com/apple/ml-mobileclip with ONNX weights to be compatible with Transformers.js.

Usage (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 classification.

import {
  AutoTokenizer,
  CLIPTextModelWithProjection,
  AutoProcessor,
  CLIPVisionModelWithProjection,
  RawImage,
  dot,
  softmax,
} from '@xenova/transformers';

const model_id = 'Xenova/mobileclip_s0';

// Load tokenizer and text model
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const text_model = await CLIPTextModelWithProjection.from_pretrained(model_id);

// Load processor and vision model
const processor = await AutoProcessor.from_pretrained(model_id);
const vision_model = await CLIPVisionModelWithProjection.from_pretrained(model_id, {
  quantized: false, // NOTE: vision model is sensitive to quantization.
});

// Run tokenization
const texts = ['cats', 'dogs', 'birds'];
const text_inputs = tokenizer(texts, { padding: 'max_length', truncation: true });

// Compute text embeddings
const { text_embeds } = await text_model(text_inputs);
const normalized_text_embeds = text_embeds.normalize().tolist();

// Read image and run processor
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg';
const image = await RawImage.read(url);
const image_inputs = await processor(image);

// Compute vision embeddings
const { image_embeds } = await vision_model(image_inputs);
const normalized_image_embeds = image_embeds.normalize().tolist();

// Compute probabilities
const probabilities = normalized_image_embeds.map(
  x => softmax(normalized_text_embeds.map(y => 100 * dot(x, y)))
);
console.log(probabilities); // [[ 0.9989384093386391, 0.001060433633052551, 0.000001157028308360134 ]]

Model info

transformers.js onnx clip mobileclip image-feature-extraction feature-extraction zero-shot-image-classification license:other region:us
↓ 2 ♥ 2

Created: 2024-08-27

Updated: 2024-08-27

View on Hugging Face

Files (21)

.gitattributes
LICENSE
README.md
config.json
onnx/text_model.onnx ONNX
onnx/text_model_bnb4.onnx ONNX
onnx/text_model_fp16.onnx ONNX
onnx/text_model_int8.onnx ONNX
onnx/text_model_q4.onnx ONNX
onnx/text_model_quantized.onnx ONNX
onnx/text_model_uint8.onnx ONNX
onnx/vision_model.onnx ONNX
onnx/vision_model_bnb4.onnx ONNX
onnx/vision_model_fp16.onnx ONNX
onnx/vision_model_int8.onnx ONNX
onnx/vision_model_q4.onnx ONNX
onnx/vision_model_quantized.onnx ONNX
onnx/vision_model_uint8.onnx ONNX
preprocessor_config.json
tokenizer.json
tokenizer_config.json

Related models