Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers.js
|
| 3 |
+
tags:
|
| 4 |
+
- pose-estimation
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
https://github.com/open-mmlab/mmpose/tree/main/projects/rtmo with ONNX weights to be compatible with Transformers.js.
|
| 10 |
+
|
| 11 |
+
## Usage (Transformers.js)
|
| 12 |
+
|
| 13 |
+
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/@xenova/transformers) using:
|
| 14 |
+
```bash
|
| 15 |
+
npm i @xenova/transformers
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
**Example:** Perform pose-estimation w/ `Xenova/RTMO-l`.
|
| 19 |
+
|
| 20 |
+
```js
|
| 21 |
+
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
|
| 22 |
+
|
| 23 |
+
// Load model and processor
|
| 24 |
+
const model_id = 'Xenova/RTMO-l';
|
| 25 |
+
const model = await AutoModel.from_pretrained(model_id);
|
| 26 |
+
const processor = await AutoProcessor.from_pretrained(model_id);
|
| 27 |
+
|
| 28 |
+
// Read image and run processor
|
| 29 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg';
|
| 30 |
+
const image = await RawImage.read(url);
|
| 31 |
+
const { pixel_values, original_sizes, reshaped_input_sizes } = await processor(image);
|
| 32 |
+
|
| 33 |
+
// Predict bounding boxes and keypoints
|
| 34 |
+
const { dets, keypoints } = await model({ input: pixel_values });
|
| 35 |
+
|
| 36 |
+
// Select the first image
|
| 37 |
+
const predicted_boxes = dets.tolist()[0];
|
| 38 |
+
const predicted_points = keypoints.tolist()[0];
|
| 39 |
+
const [height, width] = original_sizes[0];
|
| 40 |
+
const [resized_height, resized_width] = reshaped_input_sizes[0];
|
| 41 |
+
|
| 42 |
+
// Compute scale values
|
| 43 |
+
const xScale = width / resized_width;
|
| 44 |
+
const yScale = height / resized_height;
|
| 45 |
+
|
| 46 |
+
// Define thresholds
|
| 47 |
+
const point_threshold = 0.3;
|
| 48 |
+
const box_threshold = 0.3;
|
| 49 |
+
|
| 50 |
+
// Display results
|
| 51 |
+
for (let i = 0; i < predicted_boxes.length; ++i) {
|
| 52 |
+
const [xmin, ymin, xmax, ymax, box_score] = predicted_boxes[i];
|
| 53 |
+
if (box_score < box_threshold) continue;
|
| 54 |
+
|
| 55 |
+
const x1 = (xmin * xScale).toFixed(2);
|
| 56 |
+
const y1 = (ymin * yScale).toFixed(2);
|
| 57 |
+
const x2 = (xmax * xScale).toFixed(2);
|
| 58 |
+
const y2 = (ymax * yScale).toFixed(2);
|
| 59 |
+
|
| 60 |
+
console.log(`Found person at [${x1}, ${y1}, ${x2}, ${y2}] with score ${box_score.toFixed(3)}`)
|
| 61 |
+
const points = predicted_points[i]; // of shape [17, 3]
|
| 62 |
+
for (let id = 0; id < points.length; ++id) {
|
| 63 |
+
const label = model.config.id2label[id];
|
| 64 |
+
const [x, y, point_score] = points[id];
|
| 65 |
+
if (point_score < point_threshold) continue;
|
| 66 |
+
console.log(` - ${label}: (${(x * xScale).toFixed(2)}, ${(y * yScale).toFixed(2)}) with score ${point_score.toFixed(3)}`);
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
<details>
|
| 72 |
+
|
| 73 |
+
<summary>See example output</summary>
|
| 74 |
+
|
| 75 |
+
```
|
| 76 |
+
Found person at [400.13, 66.05, 657.48, 496.67] with score 0.978
|
| 77 |
+
- nose: (520.40, 118.17) with score 0.445
|
| 78 |
+
- left_eye: (531.83, 111.10) with score 0.350
|
| 79 |
+
- left_shoulder: (559.65, 168.66) with score 0.999
|
| 80 |
+
- right_shoulder: (469.70, 160.04) with score 0.999
|
| 81 |
+
- left_elbow: (573.20, 237.82) with score 1.000
|
| 82 |
+
- right_elbow: (438.51, 218.06) with score 0.999
|
| 83 |
+
- left_wrist: (604.74, 308.75) with score 0.999
|
| 84 |
+
- right_wrist: (495.52, 219.24) with score 0.999
|
| 85 |
+
- left_hip: (537.36, 306.24) with score 1.000
|
| 86 |
+
- right_hip: (477.61, 314.79) with score 0.998
|
| 87 |
+
- left_knee: (576.44, 360.67) with score 1.000
|
| 88 |
+
- right_knee: (500.26, 448.33) with score 0.997
|
| 89 |
+
- left_ankle: (575.94, 461.43) with score 0.998
|
| 90 |
+
- right_ankle: (525.18, 436.10) with score 0.996
|
| 91 |
+
Found person at [84.74, 11.57, 524.53, 535.62] with score 0.970
|
| 92 |
+
- left_shoulder: (240.00, 106.15) with score 0.998
|
| 93 |
+
- right_shoulder: (230.72, 131.27) with score 0.999
|
| 94 |
+
- left_elbow: (319.58, 164.42) with score 0.999
|
| 95 |
+
- right_elbow: (232.16, 226.10) with score 1.000
|
| 96 |
+
- left_wrist: (390.95, 220.65) with score 0.999
|
| 97 |
+
- right_wrist: (157.61, 227.93) with score 0.999
|
| 98 |
+
- left_hip: (363.29, 249.14) with score 1.000
|
| 99 |
+
- right_hip: (337.65, 250.50) with score 1.000
|
| 100 |
+
- left_knee: (297.35, 368.55) with score 1.000
|
| 101 |
+
- right_knee: (328.29, 390.84) with score 1.000
|
| 102 |
+
- left_ankle: (433.81, 343.83) with score 0.999
|
| 103 |
+
- right_ankle: (452.74, 504.60) with score 0.995
|
| 104 |
+
Found person at [-4.11, 53.42, 174.91, 372.64] with score 0.644
|
| 105 |
+
- nose: (74.67, 84.38) with score 0.375
|
| 106 |
+
- left_shoulder: (114.29, 113.60) with score 0.991
|
| 107 |
+
- right_shoulder: (44.21, 117.73) with score 0.989
|
| 108 |
+
- left_elbow: (124.69, 159.42) with score 0.978
|
| 109 |
+
- right_elbow: (26.54, 154.78) with score 0.995
|
| 110 |
+
- left_wrist: (132.86, 168.78) with score 0.957
|
| 111 |
+
- right_wrist: (6.44, 195.67) with score 0.986
|
| 112 |
+
- left_hip: (98.90, 199.49) with score 0.978
|
| 113 |
+
- right_hip: (62.77, 200.49) with score 0.976
|
| 114 |
+
- left_knee: (111.91, 277.06) with score 0.998
|
| 115 |
+
- right_knee: (65.08, 276.40) with score 0.999
|
| 116 |
+
- left_ankle: (128.95, 344.65) with score 0.973
|
| 117 |
+
- right_ankle: (63.55, 345.60) with score 0.992
|
| 118 |
+
Found person at [511.40, 32.53, 658.71, 345.63] with score 0.384
|
| 119 |
+
- nose: (554.88, 74.25) with score 0.796
|
| 120 |
+
- left_eye: (563.64, 68.39) with score 0.716
|
| 121 |
+
- right_eye: (547.38, 68.22) with score 0.542
|
| 122 |
+
- left_ear: (575.42, 72.40) with score 0.324
|
| 123 |
+
- left_shoulder: (576.47, 105.27) with score 0.999
|
| 124 |
+
- right_shoulder: (531.19, 105.55) with score 0.956
|
| 125 |
+
- left_elbow: (623.35, 151.54) with score 0.999
|
| 126 |
+
- right_elbow: (549.79, 144.36) with score 0.387
|
| 127 |
+
- left_wrist: (631.33, 198.37) with score 0.991
|
| 128 |
+
- right_wrist: (547.36, 162.58) with score 0.486
|
| 129 |
+
- left_hip: (578.36, 192.67) with score 0.989
|
| 130 |
+
- right_hip: (555.21, 188.00) with score 0.925
|
| 131 |
+
- left_knee: (604.56, 239.95) with score 0.977
|
| 132 |
+
- right_knee: (545.23, 221.37) with score 0.952
|
| 133 |
+
- left_ankle: (587.82, 323.26) with score 0.401
|
| 134 |
+
- right_ankle: (546.77, 322.69) with score 0.846
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
</details>
|