Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deepomatic/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, *args, **kwargs):
More details in the `requests` documentation: https://2.python-requests.org/en/master/user/advanced/#timeouts
:type requests_timeout: float or tuple(float, float)
:param http_retry (optional): Customize the retry of http errors.
Defaults to `HTTPRetry()`. Check out `http_retry.HTTPRetry` documentation for more information about the parameters and default values.
Defaults to `HTTPRetry()`. See `http_retry.HTTPRetry` documentation for details about parameters and default values.
If `None`, no retry will be done on errors.
:type http_retry: http_retry.HTTPRetry

Expand Down
3 changes: 2 additions & 1 deletion deepomatic/api/http_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def __init__(self, app_id=None, api_key=None, verify_ssl=None,
if api_key is None:
api_key = os.getenv('DEEPOMATIC_API_KEY')
if app_id is None or api_key is None:
raise DeepomaticException("Please specify 'app_id' and 'api_key' either by passing those values to the client or by defining the DEEPOMATIC_APP_ID and DEEPOMATIC_API_KEY environment variables.")
raise DeepomaticException("Please specify 'app_id' and 'api_key' either by passing those values to the client"
" or by defining the DEEPOMATIC_APP_ID and DEEPOMATIC_API_KEY environment variables.")

if not isinstance(version, string_types):
version = 'v%g' % version
Expand Down
16 changes: 8 additions & 8 deletions deepomatic/api/http_retry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import functools

from deepomatic.api import utils
from deepomatic.api.exceptions import HTTPRetryError
from requests.exceptions import (ProxyError, RequestException,
Expand All @@ -12,8 +10,8 @@ class retry_if_exception_type(retry_if_exception):
# Taken from https://github.com/jd/tenacity/blob/2775f13b34b3ec67a774061a77fcd4e1e9b4157c/tenacity/retry.py#L72
# Extented to support blacklist types
def __predicate(self, e):
return (isinstance(e, self.exception_types) and
not isinstance(e, self.exception_types_blacklist))
return (isinstance(e, self.exception_types)
and not isinstance(e, self.exception_types_blacklist))

def __init__(self, exception_types=Exception,
exception_types_blacklist=()):
Expand Down Expand Up @@ -46,7 +44,9 @@ class HTTPRetry(object):
wait_fixed(0.1) + random_wait)
```
:type wait: tenacity.wait_base
:param stop (optional). Tell when to stop retrying. By default it stops retrying after a delay of 60 seconds. A last retry can be done just before this delay is reached, thus the total amount of elapsed time might be a bit higher. More details in tenacity source code https://github.com/jd/tenacity/blob/5.1.1/tenacity/stop.py
:param stop (optional). Tell when to stop retrying. By default it stops retrying after a delay of 60 seconds.
A last retry can be done just before this delay is reached, thus the total amount of elapsed time might be a bit higher.
More details in tenacity source code https://github.com/jd/tenacity/blob/5.1.1/tenacity/stop.py
Raises tenacity.RetryError when timeout is reached.
:type timeout: tenacity.stop_base
"""
Expand All @@ -69,9 +69,9 @@ def __init__(self, retry_if=None, wait=None, stop=None):

if self.retry_if is None:
self.retry_status_code = set(HTTPRetry.Default.RETRY_STATUS_CODES)
self.retry_if = (retry_if_result(self.retry_if_status_code) |
retry_if_exception_type(HTTPRetry.Default.RETRY_EXCEPTION_TYPES,
HTTPRetry.Default.RETRY_EXCEPTION_TYPES_BLACKLIST))
self.retry_if = (retry_if_result(self.retry_if_status_code)
| retry_if_exception_type(HTTPRetry.Default.RETRY_EXCEPTION_TYPES,
HTTPRetry.Default.RETRY_EXCEPTION_TYPES_BLACKLIST))

if self.wait is None:
random_wait = wait_random_exponential(multiplier=HTTPRetry.Default.RETRY_EXP_MULTIPLIER,
Expand Down
3 changes: 2 additions & 1 deletion deepomatic/api/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def __init__(self, source, encoding=None):
is_file = hasattr(source, 'read')
is_raw = False
if not is_file:
is_raw = (sys.version_info >= (3, 0) and isinstance(source, bytes)) or not any([source.startswith(p) for p in self.supported_protocols])
is_raw = ((sys.version_info >= (3, 0) and isinstance(source, bytes))
or not any([source.startswith(p) for p in self.supported_protocols]))
if is_raw:
if encoding is None:
raise DeepomaticException("You must specify 'encoding' when passing raw data")
Expand Down
1 change: 1 addition & 0 deletions deepomatic/api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ResourceList(Resource):
"""
This is an helper to access a resource list.
"""

def __init__(self, resource_class, helper, uri, offset=None, limit=None, **kwargs):
params = copy.deepcopy(kwargs)
if offset is not None:
Expand Down
8 changes: 4 additions & 4 deletions deepomatic/api/resources/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Network(ListableResource,
This is an helper to manipulate a 'Network' object.
"""
object_template = {
'name': RequiredArg(),
'description': OptionnalArg(),
'metadata': OptionnalArg(),
'framework': ImmutableArg(),
'name': RequiredArg(),
'description': OptionnalArg(),
'metadata': OptionnalArg(),
'framework': ImmutableArg(),
'preprocessing': ImmutableArg(),
'postprocessings': OptionnalArg(mutable=False),
}
Expand Down
10 changes: 5 additions & 5 deletions deepomatic/api/resources/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class RecognitionSpec(ListableResource,
This is an helper to manipulate a 'Recognition Specification' object.
"""
object_template = {
'name': RequiredArg(),
'name': RequiredArg(),
'description': OptionnalArg(),
'metadata': OptionnalArg(),
'outputs': ImmutableArg(),
'metadata': OptionnalArg(),
'outputs': ImmutableArg(),
'current_version_id': UpdateOnlyArg()
}

Expand All @@ -72,7 +72,7 @@ class RecognitionVersion(CreateableResource,
base_uri = '/recognition/versions/'

object_template = {
'spec_id': RequiredArg(),
'network_id': RequiredArg(),
'spec_id': RequiredArg(),
'network_id': RequiredArg(),
'post_processings': RequiredArg(),
}
4 changes: 2 additions & 2 deletions deepomatic/api/resources/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def wait(self, **retry_kwargs):
"""
try:
retry_get_tasks(self._refresh_status,
retry_if_exception_type(HTTPRetryError) |
retry_if_result(is_pending_status),
retry_if_exception_type(HTTPRetryError)
| retry_if_result(is_pending_status),
**retry_kwargs)
except TaskRetryError as retry_error:
raise TaskTimeout(self._data, retry_error)
Expand Down
4 changes: 3 additions & 1 deletion demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ def demo(client=None):
logger.info(result)

print_header("Run inference on specific version with a bounding box")
result = version.inference(inputs=[ImageInput(demo_url, bbox={"xmin": 0.1, "ymin": 0.1, "xmax": 0.9, "ymax": 0.9})], show_discarded=True, max_predictions=3)
result = version.inference(inputs=[ImageInput(demo_url, bbox={"xmin": 0.1, "ymin": 0.1, "xmax": 0.9, "ymax": 0.9})],
show_discarded=True,
max_predictions=3)
logger.info(result)

"""
Expand Down
2 changes: 2 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM ${BASE_IMAGE} as builder

WORKDIR /app
COPY . .
# lint check
RUN flake8 --statistics --verbose
RUN python setup.py bdist_wheel


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ promise>=2.1,<3
six>=1.10.0,<2
requests>=2.19.0,<3 # will not work below in python3
tenacity>=5.1,<6
flake8>=3.7,<4
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ universal = 1

[metadata]
license_file = LICENSE

[flake8]
max-line-length = 140
ignore = W503
exclude =
.git,
__pycache__,
build,
dist
11 changes: 7 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def custom_network(client):

model_file = os.path.join(extract_dir, model_file_name)
mean_file = os.path.join(extract_dir, mean_file_name)
variables_file = os.path.join(extract_dir+'/variables/', variables_file_name)
variables_data_file = os.path.join(extract_dir+'/variables/', variables_data_file_name)
variables_file = os.path.join(extract_dir + '/variables/', variables_file_name)
variables_data_file = os.path.join(extract_dir + '/variables/', variables_data_file_name)

if not os.path.exists(model_file):
with zipfile.ZipFile(net_zip) as f:
Expand Down Expand Up @@ -170,7 +170,8 @@ class TestClient(object):
def test_headers(self, client):
http_helper = client.http_helper
session_headers = http_helper.session.headers
assert session_headers['User-Agent'].startswith('{}-tests/{} {}-python-client/{}'.format(__title__, __version__, __title__, __version__))
assert session_headers['User-Agent'].startswith(
'{}-tests/{} {}-python-client/{}'.format(__title__, __version__, __title__, __version__))
assert 'platform/' in session_headers['User-Agent']
assert 'python/' in session_headers['User-Agent']
assert session_headers['X-APP-ID']
Expand Down Expand Up @@ -254,7 +255,9 @@ def test_create_custom_reco_and_infer(self, client, custom_network):
result = spec.inference(inputs=[ImageInput(DEMO_URL)], show_discarded=False, max_predictions=3)
assert inference_schema(2, 0, 'golden retriever', 0.8) == result

result = version.inference(inputs=[ImageInput(DEMO_URL, bbox={"xmin": 0.1, "ymin": 0.1, "xmax": 0.9, "ymax": 0.9})], show_discarded=True, max_predictions=3)
result = version.inference(inputs=[ImageInput(DEMO_URL, bbox={"xmin": 0.1, "ymin": 0.1, "xmax": 0.9, "ymax": 0.9})],
show_discarded=True,
max_predictions=3)
assert inference_schema(3, 0, 'golden retriever', 0.5) == result

versions = spec.versions()
Expand Down