Example:
Perform image captioning with
onnx-community/Florence-2-large-ft
.
import {
Florence2ForConditionalGeneration,
AutoProcessor,
AutoTokenizer,
RawImage,
} from'@xenova/transformers';
// Load model, processor, and tokenizerconst model_id = 'onnx-community/Florence-2-large-ft';
const model = awaitFlorence2ForConditionalGeneration.from_pretrained(model_id, {
dtype: {
embed_tokens: 'fp16', // or 'fp32'vision_encoder: 'fp16', // or 'fp32'encoder_model: 'q4',
decoder_model_merged: 'q4',
},
});
const processor = awaitAutoProcessor.from_pretrained(model_id);
const tokenizer = awaitAutoTokenizer.from_pretrained(model_id);
// Load image and prepare vision inputsconst url = 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg';
const image = awaitRawImage.fromURL(url);
const vision_inputs = awaitprocessor(image);
// Specify task and prepare text inputsconst task = '<MORE_DETAILED_CAPTION>';
const prompts = processor.construct_prompts(task);
const text_inputs = tokenizer(prompts);
// Generate textconst generated_ids = await model.generate({
...text_inputs,
...vision_inputs,
max_new_tokens: 256,
});
// Decode generated textconst generated_text = tokenizer.batch_decode(generated_ids, { skip_special_tokens: false })[0];
// Post-process the generated textconst result = processor.post_process_generation(generated_text, task, image.size);
console.log(result);
// { '<MORE_DETAILED_CAPTION>': 'A car is parked on the street. The car is a light green color. The doors on the building are brown. The building is a yellow color. There are two doors on both sides of the car. The wheels on the car are very shiny. The ground is made of bricks. The sky is blue. The sun is shining on the top of the building.' }
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
).
Runs of onnx-community Florence-2-large-ft on huggingface.co
1.6K
Total runs
0
24-hour runs
110
3-day runs
112
7-day runs
437
30-day runs
More Information About Florence-2-large-ft huggingface.co Model
Florence-2-large-ft huggingface.co is an AI model on huggingface.co that provides Florence-2-large-ft's model effect (), which can be used instantly with this onnx-community Florence-2-large-ft model. huggingface.co supports a free trial of the Florence-2-large-ft model, and also provides paid use of the Florence-2-large-ft. Support call Florence-2-large-ft model through api, including Node.js, Python, http.
Florence-2-large-ft huggingface.co is an online trial and call api platform, which integrates Florence-2-large-ft's modeling effects, including api services, and provides a free online trial of Florence-2-large-ft, you can try Florence-2-large-ft online for free by clicking the link below.
onnx-community Florence-2-large-ft online free url in huggingface.co:
Florence-2-large-ft is an open source model from GitHub that offers a free installation service, and any user can find Florence-2-large-ft on GitHub to install. At the same time, huggingface.co provides the effect of Florence-2-large-ft install, users can directly use Florence-2-large-ft installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
Florence-2-large-ft install url in huggingface.co: