Views
No views yet
npm i @huggingface/transformersXenova/gelan-e_all.1import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
2
3// Load model
4const model = await AutoModel.from_pretrained('Xenova/gelan-e_all', {
5 dtype: 'fp32', // (Optional) Use unquantized version.
6})
7
8// Load processor
9const processor = await AutoProcessor.from_pretrained('Xenova/gelan-e_all');
10// processor.feature_extractor.size = { shortest_edge: 128 } // (Optional) Update resize value
11
12// Read image and run processor
13const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
14const image = await RawImage.read(url);
15const inputs = await processor(image);
16
17// Run object detection
18const threshold = 0.3;
19const { outputs } = await model(inputs);
20const predictions = outputs.tolist();
21
22for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
23 if (score < threshold) break;
24 const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
25 console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
26}
27// Found "car" at [157.78, 132.88, 223.89, 167.56] with score 0.89.
28// Found "car" at [62.69, 120.29, 140.12, 146.40] with score 0.86.
29// Found "bicycle" at [0.53, 180.42, 39.41, 204.48] with score 0.84.
30// Found "bicycle" at [157.39, 163.91, 194.82, 189.06] with score 0.81.
31// Found "person" at [192.77, 90.67, 207.29, 116.15] with score 0.80.
32// Found "bicycle" at [124.00, 183.29, 162.22, 206.57] with score 0.78.
33// Found "person" at [11.91, 164.63, 27.64, 200.17] with score 0.78.
34// Found "person" at [166.75, 150.84, 187.49, 186.04] with score 0.74.
35// ...onnx).