gelan-c_all / README.md
Xenova's picture
Xenova HF Staff
Add/update the quantized ONNX model files and README.md for Transformers.js v3 (#2)
3c1ec82 verified
---
library_name: transformers.js
license: gpl-3.0
pipeline_tag: object-detection
---
https://github.com/WongKinYiu/yolov9 with ONNX weights to be compatible with Transformers.js.
## Usage (Transformers.js)
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
```bash
npm i @huggingface/transformers
```
**Example:** Perform object-detection with `Xenova/gelan-c_all`.
```js
import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
// Load model
const model = await AutoModel.from_pretrained('Xenova/gelan-c_all', {
dtype: "fp32", // (Optional) Use unquantized version.
})
// Load processor
const processor = await AutoProcessor.from_pretrained('Xenova/gelan-c_all');
// processor.feature_extractor.size = { shortest_edge: 128 } // (Optional) Update resize value
// Read image and run processor
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
const image = await RawImage.read(url);
const inputs = await processor(image);
// Run object detection
const threshold = 0.3;
const { outputs } = await model(inputs);
const predictions = outputs.tolist();
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
if (score < threshold) break;
const bbox = [xmin, ymin, xmax, ymax].map(x => x.toFixed(2)).join(', ')
console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`)
}
// Found "car" at [63.06, 118.80, 139.61, 146.78] with score 0.84.
// Found "bicycle" at [158.32, 166.13, 195.02, 189.03] with score 0.81.
// Found "bicycle" at [123.22, 183.83, 162.71, 206.30] with score 0.79.
// Found "bicycle" at [0.56, 180.92, 39.26, 203.94] with score 0.78.
// Found "car" at [157.10, 132.38, 223.72, 167.69] with score 0.77.
// Found "person" at [193.04, 90.98, 207.09, 116.78] with score 0.77.
// Found "person" at [12.49, 164.97, 27.63, 197.55] with score 0.66.
// Found "traffic light" at [102.80, 74.25, 124.12, 95.75] with score 0.62.
// ...
```
## Demo
Test it out [here](https://huggingface.co/spaces/Xenova/video-object-detection)!
<video controls autoplay loop src="/static-proxy?url=https%3A%2F%2Fcdn-uploads.huggingface.co%2Fproduction%2Fuploads%2F61b253b7ac5ecaae3d1efe0c%2FAgNFx_3cPMh5zjR91n9Dt.mp4%26quot%3B%3C%2Fspan%3E%26gt%3B%3C%2Fspan%3E%3C%2Fspan%3E%3Cspan class="language-xml"></video>
---
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](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).