Update README.md
Browse files
README.md
CHANGED
|
@@ -34,24 +34,26 @@ const processor = await AutoProcessor.from_pretrained('onnx-community/yolov10b')
|
|
| 34 |
// Read image and run processor
|
| 35 |
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
| 36 |
const image = await RawImage.read(url);
|
| 37 |
-
const { pixel_values } = await processor(image);
|
| 38 |
|
| 39 |
// Run object detection
|
| 40 |
const { output0 } = await model({ images: pixel_values });
|
| 41 |
const predictions = output0.tolist()[0];
|
|
|
|
| 42 |
const threshold = 0.5;
|
|
|
|
|
|
|
| 43 |
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
| 44 |
if (score < threshold) continue;
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
-
// Found "car" at [
|
| 49 |
-
// Found "car" at [
|
| 50 |
-
// Found "bicycle" at [
|
| 51 |
-
// Found "bicycle" at [
|
| 52 |
-
// Found "person" at [
|
| 53 |
-
// Found "bicycle" at [1.51, 517.97, 110.14, 584.14] with score 0.90.
|
| 54 |
-
// Found "person" at [31.05, 469.64, 79.11, 567.90] with score 0.90.
|
| 55 |
-
// Found "person" at [394.04, 479.20, 442.46, 587.36] with score 0.89.
|
| 56 |
// ...
|
| 57 |
```
|
|
|
|
| 34 |
// Read image and run processor
|
| 35 |
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/city-streets.jpg';
|
| 36 |
const image = await RawImage.read(url);
|
| 37 |
+
const { pixel_values, reshaped_input_sizes } = await processor(image);
|
| 38 |
|
| 39 |
// Run object detection
|
| 40 |
const { output0 } = await model({ images: pixel_values });
|
| 41 |
const predictions = output0.tolist()[0];
|
| 42 |
+
|
| 43 |
const threshold = 0.5;
|
| 44 |
+
const [newHeight, newWidth] = reshaped_input_sizes[0]; // Reshaped height and width
|
| 45 |
+
const [xs, ys] = [image.width / newWidth, image.height / newHeight]; // x and y resize scales
|
| 46 |
for (const [xmin, ymin, xmax, ymax, score, id] of predictions) {
|
| 47 |
if (score < threshold) continue;
|
| 48 |
+
|
| 49 |
+
// Convert to original image coordinates
|
| 50 |
+
const bbox = [xmin * xs, ymin * ys, xmax * xs, ymax * ys].map(x => x.toFixed(2)).join(', ');
|
| 51 |
+
console.log(`Found "${model.config.id2label[id]}" at [${bbox}] with score ${score.toFixed(2)}.`);
|
| 52 |
}
|
| 53 |
+
// Found "car" at [559.30, 472.72, 799.58, 598.15] with score 0.95.
|
| 54 |
+
// Found "car" at [221.91, 422.56, 498.09, 521.85] with score 0.94.
|
| 55 |
+
// Found "bicycle" at [1.59, 646.99, 137.72, 730.35] with score 0.92.
|
| 56 |
+
// Found "bicycle" at [561.25, 593.65, 695.01, 671.73] with score 0.91.
|
| 57 |
+
// Found "person" at [687.74, 324.93, 739.70, 415.04] with score 0.89.
|
|
|
|
|
|
|
|
|
|
| 58 |
// ...
|
| 59 |
```
|