Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-m`.
|
19 |
+
|
20 |
+
```js
|
21 |
+
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
|
22 |
+
|
23 |
+
// Load model and processor
|
24 |
+
const model_id = 'Xenova/RTMO-m';
|
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 [394.23, 54.52, 676.59, 509.93] with score 0.977
|
77 |
+
- nose: (521.88, 120.59) with score 0.692
|
78 |
+
- left_eye: (536.24, 109.29) with score 0.635
|
79 |
+
- right_eye: (511.85, 107.62) with score 0.651
|
80 |
+
- left_shoulder: (561.11, 171.55) with score 0.993
|
81 |
+
- right_shoulder: (471.06, 157.17) with score 0.999
|
82 |
+
- left_elbow: (574.33, 240.08) with score 0.993
|
83 |
+
- right_elbow: (437.67, 219.04) with score 0.998
|
84 |
+
- left_wrist: (605.09, 310.85) with score 0.996
|
85 |
+
- right_wrist: (496.67, 218.61) with score 0.993
|
86 |
+
- left_hip: (537.65, 305.16) with score 1.000
|
87 |
+
- right_hip: (475.64, 313.71) with score 1.000
|
88 |
+
- left_knee: (581.28, 366.44) with score 1.000
|
89 |
+
- right_knee: (506.58, 432.27) with score 0.996
|
90 |
+
- left_ankle: (575.49, 470.17) with score 0.999
|
91 |
+
- right_ankle: (534.34, 442.35) with score 0.994
|
92 |
+
Found person at [65.64, -3.94, 526.84, 538.72] with score 0.947
|
93 |
+
- left_shoulder: (224.52, 111.13) with score 0.996
|
94 |
+
- right_shoulder: (212.09, 110.60) with score 0.998
|
95 |
+
- left_elbow: (322.33, 170.98) with score 0.998
|
96 |
+
- right_elbow: (235.17, 223.79) with score 1.000
|
97 |
+
- left_wrist: (389.08, 222.90) with score 0.997
|
98 |
+
- right_wrist: (162.75, 228.10) with score 0.998
|
99 |
+
- left_hip: (365.58, 242.19) with score 1.000
|
100 |
+
- right_hip: (327.40, 255.20) with score 1.000
|
101 |
+
- left_knee: (313.14, 376.06) with score 1.000
|
102 |
+
- right_knee: (336.28, 393.63) with score 1.000
|
103 |
+
- left_ankle: (428.03, 347.03) with score 1.000
|
104 |
+
- right_ankle: (434.31, 510.29) with score 0.992
|
105 |
+
Found person at [-0.88, 48.03, 182.29, 381.19] with score 0.787
|
106 |
+
- nose: (72.50, 83.26) with score 0.606
|
107 |
+
- left_eye: (81.11, 76.66) with score 0.627
|
108 |
+
- right_eye: (64.49, 77.73) with score 0.641
|
109 |
+
- left_ear: (95.29, 78.63) with score 0.513
|
110 |
+
- left_shoulder: (114.15, 109.26) with score 0.918
|
111 |
+
- right_shoulder: (46.66, 115.12) with score 0.988
|
112 |
+
- left_elbow: (131.40, 160.25) with score 0.351
|
113 |
+
- right_elbow: (26.67, 159.11) with score 0.934
|
114 |
+
- right_wrist: (6.60, 201.80) with score 0.681
|
115 |
+
- left_hip: (110.48, 206.96) with score 0.998
|
116 |
+
- right_hip: (60.89, 199.41) with score 0.997
|
117 |
+
- left_knee: (118.23, 272.23) with score 0.999
|
118 |
+
- right_knee: (66.52, 273.32) with score 0.994
|
119 |
+
- left_ankle: (129.82, 346.46) with score 0.999
|
120 |
+
- right_ankle: (60.40, 349.13) with score 0.995
|
121 |
+
Found person at [512.82, 31.30, 662.28, 314.57] with score 0.451
|
122 |
+
- nose: (550.07, 74.26) with score 0.766
|
123 |
+
- left_eye: (558.96, 67.14) with score 0.955
|
124 |
+
- right_eye: (541.52, 68.23) with score 0.783
|
125 |
+
- left_ear: (575.04, 67.61) with score 0.952
|
126 |
+
- left_shoulder: (589.39, 102.33) with score 0.996
|
127 |
+
- right_shoulder: (511.02, 103.00) with score 0.699
|
128 |
+
- left_elbow: (626.71, 148.71) with score 0.997
|
129 |
+
- left_wrist: (633.15, 200.33) with score 0.982
|
130 |
+
- left_hip: (580.00, 181.21) with score 0.994
|
131 |
+
- right_hip: (524.41, 184.62) with score 0.849
|
132 |
+
- left_knee: (594.99, 244.95) with score 0.977
|
133 |
+
- right_knee: (533.72, 246.37) with score 0.504
|
134 |
+
- left_ankle: (598.47, 294.18) with score 0.844
|
135 |
+
Found person at [771.50, 136.02, 800.52, 278.18] with score 0.356
|
136 |
+
- right_shoulder: (792.82, 182.43) with score 0.819
|
137 |
+
- right_elbow: (794.75, 207.33) with score 0.753
|
138 |
+
```
|
139 |
+
|
140 |
+
</details>
|