Skip to content

Commit 3a156f1

Browse files
committed
support min_confidence
1 parent 06ca915 commit 3a156f1

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

deepstack/core.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ def get_objects_summary(predictions: List[Dict]):
9393

9494

9595
def post_image(
96-
url: str, image_bytes: bytes, api_key: str, timeout: int, data: dict = {}
96+
url: str, image_bytes: bytes, timeout: int, data: dict
9797
) -> requests.models.Response:
9898
"""Post an image to Deepstack. Only handles exceptions."""
9999
try:
100-
data["api_key"] = api_key # Insert the api_key
101100
return requests.post(
102101
url, files={"image": image_bytes}, data=data, timeout=timeout
103102
)
@@ -112,12 +111,17 @@ def post_image(
112111

113112

114113
def process_image(
115-
url: str, image_bytes: bytes, api_key: str, timeout: int, data: dict = {}
114+
url: str,
115+
image_bytes: bytes,
116+
api_key: str,
117+
min_confidence: float,
118+
timeout: int,
119+
data: dict = {},
116120
) -> Dict:
117121
"""Process image_bytes and detect. Handles common status codes"""
118-
response = post_image(
119-
url=url, image_bytes=image_bytes, api_key=api_key, timeout=timeout, data=data
120-
)
122+
data["api_key"] = api_key
123+
data["min_confidence"] = min_confidence
124+
response = post_image(url=url, image_bytes=image_bytes, timeout=timeout, data=data)
121125
if response.status_code == HTTP_OK:
122126
return response.json()
123127
elif response.status_code == BAD_URL:
@@ -194,6 +198,7 @@ def detect(self, image_bytes: bytes):
194198
url=self._url_detect,
195199
image_bytes=image_bytes,
196200
api_key=self._api_key,
201+
min_confidence=self._min_confidence,
197202
timeout=self._timeout,
198203
)
199204
return response["predictions"]
@@ -225,6 +230,7 @@ def recognize(self, image_bytes: bytes):
225230
url=self._url_recognize,
226231
image_bytes=image_bytes,
227232
api_key=self._api_key,
233+
min_confidence=self._min_confidence,
228234
timeout=self._timeout,
229235
)
230236
del response["success"]
@@ -259,6 +265,7 @@ def detect(self, image_bytes: bytes):
259265
url=self._url_detect,
260266
image_bytes=image_bytes,
261267
api_key=self._api_key,
268+
min_confidence=self._min_confidence,
262269
timeout=self._timeout,
263270
)
264271
return response["predictions"]
@@ -271,6 +278,7 @@ def register(self, name: str, image_bytes: bytes):
271278
url=self._url_register,
272279
image_bytes=image_bytes,
273280
api_key=self._api_key,
281+
min_confidence=self._min_confidence,
274282
timeout=self._timeout,
275283
data={"userid": name},
276284
)
@@ -290,6 +298,7 @@ def recognize(self, image_bytes: bytes):
290298
url=self._url_recognize,
291299
image_bytes=image_bytes,
292300
api_key=self._api_key,
301+
min_confidence=self._min_confidence,
293302
timeout=self._timeout,
294303
)
295304

usage-object-detection.ipynb

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"IP = 'localhost'\n",
3030
"PORT = '80'\n",
3131
"API_KEY = \"\"\n",
32-
"TIMEOUT = 20 # Default is 10"
32+
"TIMEOUT = 20 # Default is 10\n",
33+
"MIN_CONFIDENCE = 0.01 # Default is 0.45"
3334
]
3435
},
3536
{
@@ -50,7 +51,7 @@
5051
"metadata": {},
5152
"outputs": [],
5253
"source": [
53-
"dsobject = ds.DeepstackObject(ip=IP, port=PORT, api_key=API_KEY, timeout=TIMEOUT)"
54+
"dsobject = ds.DeepstackObject(ip=IP, port=PORT, api_key=API_KEY, timeout=TIMEOUT, min_confidence=MIN_CONFIDENCE)"
5455
]
5556
},
5657
{
@@ -93,8 +94,8 @@
9394
"name": "stdout",
9495
"output_type": "stream",
9596
"text": [
96-
"CPU times: user 7.59 ms, sys: 4.3 ms, total: 11.9 ms\n",
97-
"Wall time: 442 ms\n"
97+
"CPU times: user 7.68 ms, sys: 3.96 ms, total: 11.6 ms\n",
98+
"Wall time: 431 ms\n"
9899
]
99100
}
100101
],
@@ -115,7 +116,19 @@
115116
{
116117
"data": {
117118
"text/plain": [
118-
"[{'confidence': 0.90210795,\n",
119+
"[{'confidence': 0.028640902,\n",
120+
" 'label': 'handbag',\n",
121+
" 'y_min': 114,\n",
122+
" 'x_min': 444,\n",
123+
" 'y_max': 522,\n",
124+
" 'x_max': 605},\n",
125+
" {'confidence': 0.037546907,\n",
126+
" 'label': 'frisbee',\n",
127+
" 'y_min': 309,\n",
128+
" 'x_min': 419,\n",
129+
" 'y_max': 333,\n",
130+
" 'x_max': 437},\n",
131+
" {'confidence': 0.90210795,\n",
119132
" 'label': 'dog',\n",
120133
" 'y_min': 348,\n",
121134
" 'x_min': 650,\n",
@@ -167,7 +180,7 @@
167180
{
168181
"data": {
169182
"text/plain": [
170-
"['dog', 'person']"
183+
"['dog', 'frisbee', 'handbag', 'person']"
171184
]
172185
},
173186
"execution_count": 7,
@@ -194,7 +207,7 @@
194207
{
195208
"data": {
196209
"text/plain": [
197-
"{'dog': 1, 'person': 2}"
210+
"{'dog': 1, 'frisbee': 1, 'handbag': 1, 'person': 2}"
198211
]
199212
},
200213
"execution_count": 8,
@@ -316,8 +329,8 @@
316329
"name": "stdout",
317330
"output_type": "stream",
318331
"text": [
319-
"CPU times: user 4.19 ms, sys: 2.03 ms, total: 6.22 ms\n",
320-
"Wall time: 273 ms\n"
332+
"CPU times: user 4.75 ms, sys: 2.3 ms, total: 7.05 ms\n",
333+
"Wall time: 350 ms\n"
321334
]
322335
}
323336
],
@@ -355,27 +368,6 @@
355368
"predictions"
356369
]
357370
},
358-
{
359-
"cell_type": "code",
360-
"execution_count": 16,
361-
"metadata": {},
362-
"outputs": [
363-
{
364-
"data": {
365-
"text/plain": [
366-
"{'a': 'a', 'b': 'b'}"
367-
]
368-
},
369-
"execution_count": 16,
370-
"metadata": {},
371-
"output_type": "execute_result"
372-
}
373-
],
374-
"source": [
375-
"data = {'a':'a', 'b':'b'}\n",
376-
"data"
377-
]
378-
},
379371
{
380372
"cell_type": "code",
381373
"execution_count": null,

0 commit comments

Comments
 (0)