Views
No views yet
npm i @xenova/transformersXenova/gelan-c.1import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
2
3// Load model
4const model = await AutoModel.from_pretrained('Xenova/gelan-c', {
5 // quantized: false, // (Optional) Use unquantized version.
6})
7
8// Load processor
9const processor = await AutoProcessor.from_pretrained('Xenova/gelan-c');
10// processor.feature_extractor.do_resize = false; // (Optional) Disable resizing
11// processor.feature_extractor.size = { width: 128, height: 128 } // (Optional) Update resize value
12
13// Read image and run processor
14const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
15const image = await RawImage.read(url);
16const { pixel_values } = await processor(image);
17
18// Run object detection
19const { outputs } = await model({ images: pixel_values })
20const predictions = outputs.tolist();
21
22for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
23 const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
24 console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
25}
26// Found "car" at [446.82, 377.56, 639.19, 477.84] with score 0.93.
27// Found "car" at [177.22, 336.87, 399.68, 417.72] with score 0.93.
28// Found "bicycle" at [1.01, 518.22, 110.25, 584.43] with score 0.91.
29// Found "bicycle" at [352.25, 526.08, 463.18, 588.02] with score 0.90.
30// Found "person" at [474.38, 430.36, 533.80, 534.33] with score 0.86.
31// Found "bicycle" at [449.59, 476.04, 555.38, 537.74] with score 0.86.
32// Found "person" at [34.38, 469.56, 79.05, 566.80] with score 0.83.
33// Found "traffic light" at [376.79, 66.41, 401.90, 111.34] with score 0.82.
34// ...onnx).