Update README.md
Browse files
README.md
CHANGED
@@ -5,6 +5,104 @@ language:
|
|
5 |
- en
|
6 |
pipeline_tag: zero-shot-object-detection
|
7 |
library_name: transformers
|
|
|
|
|
|
|
|
|
8 |
---
|
9 |
|
10 |
-
# Fork of [omlab/omdet-turbo-swin-tiny-hf](https://huggingface.co/omlab/omdet-turbo-swin-tiny-hf) for a `zero-shot-object-detection` Inference endpoint.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
- en
|
6 |
pipeline_tag: zero-shot-object-detection
|
7 |
library_name: transformers
|
8 |
+
base_model:
|
9 |
+
- omlab/omdet-turbo-swin-tiny-hf
|
10 |
+
tags:
|
11 |
+
- endpoints-template
|
12 |
---
|
13 |
|
14 |
+
# Fork of [omlab/omdet-turbo-swin-tiny-hf](https://huggingface.co/omlab/omdet-turbo-swin-tiny-hf) for a `zero-shot-object-detection` Inference endpoint.
|
15 |
+
|
16 |
+
This repository implements a `custom` task for `zero-shot-object-detection` for 🤗 Inference Endpoints. The code for the customized handler is in the [handler.py](https://huggingface.co/Blueway/inference-endpoint-for-omdet-turbo-swin-tiny-hf/blob/main/handler.py).
|
17 |
+
|
18 |
+
To use deploy this model a an Inference Endpoint you have to select `Custom` as task to use the `handler.py` file.
|
19 |
+
|
20 |
+
The repository contains a requirements.txt to download the timm library.
|
21 |
+
|
22 |
+
### expected Request payload
|
23 |
+
|
24 |
+
```json
|
25 |
+
{
|
26 |
+
"image": "/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAMCAgICAgMC....", // base64 image as bytes
|
27 |
+
"candiates":["broken curb", "broken road", "broken road sign", "broken sidewalk"]
|
28 |
+
}
|
29 |
+
```
|
30 |
+
|
31 |
+
below is an example on how to run a request using Python and `requests`.
|
32 |
+
|
33 |
+
## Run Request
|
34 |
+
|
35 |
+
``` python
|
36 |
+
import json
|
37 |
+
from typing import List
|
38 |
+
import requests as r
|
39 |
+
import base64
|
40 |
+
|
41 |
+
ENDPOINT_URL = ""
|
42 |
+
HF_TOKEN = ""
|
43 |
+
|
44 |
+
def predict(path_to_image: str = None, candidates: List[str] = None):
|
45 |
+
with open(path_to_image, "rb") as i:
|
46 |
+
b64 = base64.b64encode(i.read())
|
47 |
+
|
48 |
+
payload = {"inputs": {"image": b64.decode("utf-8"), "candidates": candidates}}
|
49 |
+
response = r.post(
|
50 |
+
ENDPOINT_URL, headers={"Authorization": f"Bearer {HF_TOKEN}"}, json=payload
|
51 |
+
)
|
52 |
+
return response.json()
|
53 |
+
|
54 |
+
|
55 |
+
prediction = predict(
|
56 |
+
path_to_image="image/brokencurb.jpg", candidates=["broken curb", "broken road", "broken road sign", "broken sidewalk"]
|
57 |
+
)
|
58 |
+
print(json.dumps(prediction, indent=2))
|
59 |
+
```
|
60 |
+
expected output
|
61 |
+
|
62 |
+
``` python
|
63 |
+
{
|
64 |
+
"boxes": [
|
65 |
+
[
|
66 |
+
1.919342041015625,
|
67 |
+
231.1556396484375,
|
68 |
+
1011.4019775390625,
|
69 |
+
680.3773193359375
|
70 |
+
],
|
71 |
+
[
|
72 |
+
610.9949951171875,
|
73 |
+
397.6180419921875,
|
74 |
+
1019.9259033203125,
|
75 |
+
510.8144226074219
|
76 |
+
],
|
77 |
+
[
|
78 |
+
1.919342041015625,
|
79 |
+
231.1556396484375,
|
80 |
+
1011.4019775390625,
|
81 |
+
680.3773193359375
|
82 |
+
],
|
83 |
+
[
|
84 |
+
786.1240234375,
|
85 |
+
68.618896484375,
|
86 |
+
916.1265869140625,
|
87 |
+
225.0513458251953
|
88 |
+
]
|
89 |
+
],
|
90 |
+
"scores": [
|
91 |
+
0.4329715967178345,
|
92 |
+
0.4215811491012573,
|
93 |
+
0.3389397859573364,
|
94 |
+
0.3133399784564972
|
95 |
+
],
|
96 |
+
"candidates": [
|
97 |
+
"broken sidewalk",
|
98 |
+
"broken road sign",
|
99 |
+
"broken road",
|
100 |
+
"broken road sign"
|
101 |
+
]
|
102 |
+
}
|
103 |
+
```
|
104 |
+
The boxes are structured like {x_min, y_min, x_max, y_max}
|
105 |
+
|
106 |
+
|
107 |
+
## Credits
|
108 |
+
|