multimodalart HF Staff commited on
Commit
030a8a5
·
verified ·
1 Parent(s): 4dd3fb0

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. .gitattributes +2 -0
  2. README.md +21 -8
  3. app.py +117 -0
  4. example1.jpg +3 -0
  5. example2.jpg +3 -0
  6. requirements.txt +9 -0
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ example1.jpg filter=lfs diff=lfs merge=lfs -text
37
+ example2.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,26 @@
1
  ---
2
- title: Detrpose
3
- emoji: 🐠
4
- colorFrom: red
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 6.20.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: DETRPose
3
+ emoji: 🏃
4
+ colorFrom: purple
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 6.15.1
 
8
  app_file: app.py
9
+ short_description: Real-time multi-person pose estimation with DETRPose-L
10
+ python_version: "3.12"
11
+ startup_duration_timeout: 30m
12
  ---
13
 
14
+ # DETRPose: Real-Time Multi-Person Pose Estimation
15
+
16
+ This Space demonstrates **DETRPose-L**, a real-time end-to-end transformer model for
17
+ multi-person pose estimation. Upload an image and the model will detect all persons
18
+ and overlay 17-keypoint COCO skeleton poses.
19
+
20
+ ## Model
21
+
22
+ - **Paper**: [DETRPose: Real-Time End-to-End Multi-Person Pose Estimation via Modified
23
+ Transformer Decoder and Novel Denoising Keypoints](https://huggingface.co/papers/2506.13027)
24
+ - **Weights**: [SebasJanampa/DETRPose_L_COCO](https://huggingface.co/SebasJanampa/DETRPose_L_COCO)
25
+ - **GitHub**: [SebastianJanampa/DETRPose](https://github.com/SebastianJanampa/DETRPose)
26
+ - **AP**: 72.5 on COCO val2017 | **Params**: 32.8M | **Latency**: 9.50ms (V100, FP16, TensorRT)
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces # MUST come before torch / any CUDA-touching import
2
+ import torch
3
+ import torchvision.transforms as T
4
+ import gradio as gr
5
+ import numpy as np
6
+ import cv2
7
+ from PIL import Image
8
+ from copy import deepcopy
9
+ from detrpose import DETR
10
+
11
+ # Load the model at module scope, .to("cuda") eagerly.
12
+ model = DETR(model="detrpose_hgnetv2_l", device="cuda")
13
+
14
+ transforms = T.Compose(
15
+ [
16
+ T.Resize((640, 640)),
17
+ T.ToTensor(),
18
+ ]
19
+ )
20
+
21
+
22
+ @spaces.GPU(duration=60)
23
+ def predict(image: "Image.Image", threshold: float = 0.5) -> "Image.Image":
24
+ """Detect multi-person poses in an image using DETRPose-L.
25
+
26
+ Args:
27
+ image: Input PIL image.
28
+ threshold: Confidence threshold for keeping detected poses.
29
+ """
30
+ if image is None:
31
+ return None
32
+
33
+ im_pil = image.convert("RGB")
34
+
35
+ w, h = im_pil.size
36
+ orig_size = torch.tensor([[w, h]]).to("cuda")
37
+
38
+ im_data = transforms(im_pil).unsqueeze(0).to("cuda")
39
+
40
+ with torch.no_grad():
41
+ outputs = model.model.model(im_data)
42
+ results = model.model.postprocessor(outputs, orig_size)
43
+
44
+ scores, labels, keypoints = results
45
+ scores = scores[0].detach().cpu().numpy()
46
+ keypoints = keypoints[0].detach().cpu().numpy()
47
+
48
+ idx = scores > threshold
49
+ valid_keypoints = keypoints[idx]
50
+
51
+ im_cv2 = cv2.cvtColor(np.array(im_pil), cv2.COLOR_RGB2BGR)
52
+ model.annotator.draw_on(im_cv2, valid_keypoints)
53
+
54
+ result_rgb = cv2.cvtColor(im_cv2, cv2.COLOR_BGR2RGB)
55
+ return Image.fromarray(result_rgb)
56
+
57
+
58
+ CSS = """
59
+ #col-container { max-width: 1100px; margin: 0 auto; }
60
+ .dark .gradio-container { color: var(--body-text-color); }
61
+ """
62
+
63
+ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
64
+ with gr.Column(elem_id="col-container"):
65
+ gr.Markdown(
66
+ "# DETRPose: Real-Time Multi-Person Pose Estimation\n"
67
+ "Upload an image to detect human poses with skeleton keypoints overlaid. "
68
+ "Powered by [DETRPose-L](https://huggingface.co/SebasJanampa/DETRPose_L_COCO) — "
69
+ "the first real-time end-to-end transformer for multi-person pose estimation."
70
+ )
71
+
72
+ with gr.Row():
73
+ with gr.Column(scale=1):
74
+ input_image = gr.Image(
75
+ type="pil", label="Input Image", sources=["upload", "clipboard"]
76
+ )
77
+ threshold_slider = gr.Slider(
78
+ minimum=0.1,
79
+ maximum=0.9,
80
+ value=0.5,
81
+ step=0.05,
82
+ label="Confidence Threshold",
83
+ )
84
+ run_btn = gr.Button("Run", variant="primary")
85
+
86
+ with gr.Column(scale=1):
87
+ output_image = gr.Image(
88
+ type="pil", label="Pose Estimation Result"
89
+ )
90
+
91
+ with gr.Accordion("Advanced settings", open=False):
92
+ gr.Markdown(
93
+ "**Confidence Threshold**: Lower this to detect more poses (may include "
94
+ "false positives). Raise it for stricter, more confident detections."
95
+ )
96
+
97
+ gr.Examples(
98
+ examples=[
99
+ ["example1.jpg", 0.5],
100
+ ["example2.jpg", 0.5],
101
+ ],
102
+ inputs=[input_image, threshold_slider],
103
+ outputs=output_image,
104
+ fn=predict,
105
+ cache_examples=True,
106
+ cache_mode="lazy",
107
+ )
108
+
109
+ run_btn.click(
110
+ fn=predict,
111
+ inputs=[input_image, threshold_slider],
112
+ outputs=output_image,
113
+ api_name="predict",
114
+ )
115
+
116
+ if __name__ == "__main__":
117
+ demo.launch(mcp_server=True)
example1.jpg ADDED

Git LFS Details

  • SHA256: 24bb77a31928404e45a0454b06f6a0bd54a8db103590c9d7917288a1e0269f05
  • Pointer size: 131 Bytes
  • Size of remote file: 321 kB
example2.jpg ADDED

Git LFS Details

  • SHA256: 8795ff243cf20405bd442631d5d1cb7e60665dd459c8d57f5764333808dd49fd
  • Pointer size: 131 Bytes
  • Size of remote file: 136 kB
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ opencv-python
2
+ omegaconf
3
+ cloudpickle
4
+ iopath
5
+ scipy
6
+ loguru
7
+ safetensors
8
+ torchvision
9
+ git+https://github.com/SebastianJanampa/DETRPose.git@inference_only