Skip to content

Commit 333cfd0

Browse files
authored
Merge pull request #33 from robmarkcole/Support-min_confidence
test custom_model
2 parents f78dae7 + 936cd59 commit 333cfd0

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

deepstack/core.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,15 @@ def __init__(
170170
port: int = DEFAULT_PORT,
171171
api_key: str = DEFAULT_API_KEY,
172172
timeout: int = DEFAULT_TIMEOUT,
173-
custom_model: str = None,
173+
custom_model: str = "",
174174
):
175-
if not custom_model:
176-
super().__init__(
177-
ip=ip,
178-
port=port,
179-
api_key=api_key,
180-
timeout=timeout,
181-
url_detect=URL_OBJECT_DETECTION,
182-
)
175+
if custom_model:
176+
url_detect = URL_CUSTOM.format(custom_model=custom_model)
183177
else:
184-
super().__init__(
185-
ip=ip,
186-
port=port,
187-
api_key=api_key,
188-
timeout=timeout,
189-
url_detect=URL_CUSTOM.format(custom_model=custom_model),
190-
)
178+
url_detect = URL_OBJECT_DETECTION
179+
super().__init__(
180+
ip=ip, port=port, api_key=api_key, timeout=timeout, url_detect=url_detect,
181+
)
191182

192183
def detect(self, image_bytes: bytes):
193184
"""Process image_bytes and detect."""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = "0.7"
3+
VERSION = "0.8"
44

55
REQUIRES = ["requests"]
66

tests/test_core.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
MOCK_IP_ADDRESS = "localhost"
77
MOCK_PORT = 80
8-
OBJ_URL = "http://{}:{}/v1/vision/detection".format(MOCK_IP_ADDRESS, MOCK_PORT)
9-
SCENE_URL = "http://{}:{}/v1/vision/scene".format(MOCK_IP_ADDRESS, MOCK_PORT)
10-
FACE_DETECTION_URL = "http://{}:{}/v1/vision/face".format(MOCK_IP_ADDRESS, MOCK_PORT)
8+
MOCK_CUSTOM_MODEL = "mask"
9+
OBJ_URL = "http://localhost:80/v1/vision/detection"
10+
OBJ_CUSTOM_URL = "http://localhost:80/v1/vision/custom/mask"
11+
SCENE_URL = "http://localhost:80/v1/vision/scene"
12+
FACE_DETECTION_URL = "http://localhost:80/v1/vision/face"
1113

1214
CONFIDENCE_THRESHOLD = 0.7
1315

@@ -97,21 +99,22 @@ def test_DeepstackObject_detect():
9799
mock_req.post(
98100
OBJ_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
99101
)
100-
101102
dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
102103
predictions = dsobject.detect(MOCK_BYTES)
103104
assert predictions == MOCK_OBJECT_PREDICTIONS
104105

105106

106-
def test_DeepstackObject_detect_timeout():
107-
"""Test a timeout. THIS SHOULD FAIL, CURRENTLY BROKEN TEST"""
108-
with pytest.raises(ds.DeepstackException) as excinfo:
109-
with requests_mock.Mocker() as mock_req:
110-
mock_req.post(OBJ_URL, exc=requests.exceptions.ConnectTimeout)
111-
dsobject = ds.DeepstackObject(MOCK_IP_ADDRESS, MOCK_PORT)
112-
dsobject.detect(MOCK_BYTES)
113-
assert False
114-
assert "SHOULD FAIL" in str(excinfo.value)
107+
def test_DeepstackObject_detect_custom():
108+
"""Test a good response from server."""
109+
with requests_mock.Mocker() as mock_req:
110+
mock_req.post(
111+
OBJ_CUSTOM_URL, status_code=ds.HTTP_OK, json=MOCK_OBJECT_DETECTION_RESPONSE
112+
)
113+
dsobject = ds.DeepstackObject(
114+
MOCK_IP_ADDRESS, MOCK_PORT, custom_model=MOCK_CUSTOM_MODEL
115+
)
116+
predictions = dsobject.detect(MOCK_BYTES)
117+
assert predictions == MOCK_OBJECT_PREDICTIONS
115118

116119

117120
def test_DeepstackScene():

usage-object-detection.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
"name": "stdout",
9494
"output_type": "stream",
9595
"text": [
96-
"CPU times: user 7.74 ms, sys: 3.7 ms, total: 11.4 ms\n",
97-
"Wall time: 411 ms\n"
96+
"CPU times: user 7.59 ms, sys: 4.3 ms, total: 11.9 ms\n",
97+
"Wall time: 442 ms\n"
9898
]
9999
}
100100
],
@@ -316,8 +316,8 @@
316316
"name": "stdout",
317317
"output_type": "stream",
318318
"text": [
319-
"CPU times: user 3.92 ms, sys: 2.3 ms, total: 6.22 ms\n",
320-
"Wall time: 228 ms\n"
319+
"CPU times: user 4.19 ms, sys: 2.03 ms, total: 6.22 ms\n",
320+
"Wall time: 273 ms\n"
321321
]
322322
}
323323
],

0 commit comments

Comments
 (0)