--- library_name: transformers.js tags: - pose-estimation license: apache-2.0 --- https://github.com/open-mmlab/mmpose/tree/main/projects/rtmo 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/@xenova/transformers) using: ```bash npm i @xenova/transformers ``` **Example:** Perform pose-estimation w/ `Xenova/RTMO-m`. ```js import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers'; // Load model and processor const model_id = 'Xenova/RTMO-m'; const model = await AutoModel.from_pretrained(model_id); const processor = await AutoProcessor.from_pretrained(model_id); // Read image and run processor const url = 'https://huggingface.co./datasets/Xenova/transformers.js-docs/resolve/main/football-match.jpg'; const image = await RawImage.read(url); const { pixel_values, original_sizes, reshaped_input_sizes } = await processor(image); // Predict bounding boxes and keypoints const { dets, keypoints } = await model({ input: pixel_values }); // Select the first image const predicted_boxes = dets.tolist()[0]; const predicted_points = keypoints.tolist()[0]; const [height, width] = original_sizes[0]; const [resized_height, resized_width] = reshaped_input_sizes[0]; // Compute scale values const xScale = width / resized_width; const yScale = height / resized_height; // Define thresholds const point_threshold = 0.3; const box_threshold = 0.4; // Display results for (let i = 0; i < predicted_boxes.length; ++i) { const [xmin, ymin, xmax, ymax, box_score] = predicted_boxes[i]; if (box_score < box_threshold) continue; const x1 = (xmin * xScale).toFixed(2); const y1 = (ymin * yScale).toFixed(2); const x2 = (xmax * xScale).toFixed(2); const y2 = (ymax * yScale).toFixed(2); console.log(`Found person at [${x1}, ${y1}, ${x2}, ${y2}] with score ${box_score.toFixed(3)}`) const points = predicted_points[i]; // of shape [17, 3] for (let id = 0; id < points.length; ++id) { const label = model.config.id2label[id]; const [x, y, point_score] = points[id]; if (point_score < point_threshold) continue; console.log(` - ${label}: (${(x * xScale).toFixed(2)}, ${(y * yScale).toFixed(2)}) with score ${point_score.toFixed(3)}`); } } ```
See example output ``` Found person at [394.23, 54.52, 676.59, 509.93] with score 0.977 - nose: (521.88, 120.59) with score 0.692 - left_eye: (536.24, 109.29) with score 0.635 - right_eye: (511.85, 107.62) with score 0.651 - left_shoulder: (561.11, 171.55) with score 0.993 - right_shoulder: (471.06, 157.17) with score 0.999 - left_elbow: (574.33, 240.08) with score 0.993 - right_elbow: (437.67, 219.04) with score 0.998 - left_wrist: (605.09, 310.85) with score 0.996 - right_wrist: (496.67, 218.61) with score 0.993 - left_hip: (537.65, 305.16) with score 1.000 - right_hip: (475.64, 313.71) with score 1.000 - left_knee: (581.28, 366.44) with score 1.000 - right_knee: (506.58, 432.27) with score 0.996 - left_ankle: (575.49, 470.17) with score 0.999 - right_ankle: (534.34, 442.35) with score 0.994 Found person at [65.64, -3.94, 526.84, 538.72] with score 0.947 - left_shoulder: (224.52, 111.13) with score 0.996 - right_shoulder: (212.09, 110.60) with score 0.998 - left_elbow: (322.33, 170.98) with score 0.998 - right_elbow: (235.17, 223.79) with score 1.000 - left_wrist: (389.08, 222.90) with score 0.997 - right_wrist: (162.75, 228.10) with score 0.998 - left_hip: (365.58, 242.19) with score 1.000 - right_hip: (327.40, 255.20) with score 1.000 - left_knee: (313.14, 376.06) with score 1.000 - right_knee: (336.28, 393.63) with score 1.000 - left_ankle: (428.03, 347.03) with score 1.000 - right_ankle: (434.31, 510.29) with score 0.992 Found person at [-0.88, 48.03, 182.29, 381.19] with score 0.787 - nose: (72.50, 83.26) with score 0.606 - left_eye: (81.11, 76.66) with score 0.627 - right_eye: (64.49, 77.73) with score 0.641 - left_ear: (95.29, 78.63) with score 0.513 - left_shoulder: (114.15, 109.26) with score 0.918 - right_shoulder: (46.66, 115.12) with score 0.988 - left_elbow: (131.40, 160.25) with score 0.351 - right_elbow: (26.67, 159.11) with score 0.934 - right_wrist: (6.60, 201.80) with score 0.681 - left_hip: (110.48, 206.96) with score 0.998 - right_hip: (60.89, 199.41) with score 0.997 - left_knee: (118.23, 272.23) with score 0.999 - right_knee: (66.52, 273.32) with score 0.994 - left_ankle: (129.82, 346.46) with score 0.999 - right_ankle: (60.40, 349.13) with score 0.995 Found person at [512.82, 31.30, 662.28, 314.57] with score 0.451 - nose: (550.07, 74.26) with score 0.766 - left_eye: (558.96, 67.14) with score 0.955 - right_eye: (541.52, 68.23) with score 0.783 - left_ear: (575.04, 67.61) with score 0.952 - left_shoulder: (589.39, 102.33) with score 0.996 - right_shoulder: (511.02, 103.00) with score 0.699 - left_elbow: (626.71, 148.71) with score 0.997 - left_wrist: (633.15, 200.33) with score 0.982 - left_hip: (580.00, 181.21) with score 0.994 - right_hip: (524.41, 184.62) with score 0.849 - left_knee: (594.99, 244.95) with score 0.977 - right_knee: (533.72, 246.37) with score 0.504 - left_ankle: (598.47, 294.18) with score 0.844 ```