Skip to content

Commit a01e455

Browse files
authored
switched to max-base and added tests (#10)
* switched to max-base and added tests * added sleep * this model is very slow to start
1 parent 3e1a73b commit a01e455

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Dockerfile
2+
README.*
3+
.idea/
4+
.git/
5+
.gitignore
6+
tests/
7+
.pytest_cache
8+
tests/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
.pytest_cache/
3+
__pycache__/

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: python
2+
python:
3+
- 3.6
4+
5+
services:
6+
- docker
7+
8+
install:
9+
- docker build -t max-inception-resnet-v2 .
10+
- docker run -it -d -p 5000:5000 max-inception-resnet-v2
11+
- sleep 30
12+
13+
before_script:
14+
- pip install pytest requests
15+
16+
script:
17+
- pytest tests/test.py

Dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
FROM continuumio/miniconda3
1+
FROM codait/max-base
22

33
ARG model_bucket=http://max-assets.s3-api.us-geo.objectstorage.softlayer.net/keras
44
ARG model_file=inception_resnet_v2.h5
55

66
WORKDIR /workspace
7-
RUN mkdir assets
8-
RUN wget -nv ${model_bucket}/${model_file} --output-document=/workspace/assets/${model_file}
7+
8+
RUN wget -nv --show-progress --progress=bar:force:noscroll ${model_bucket}/${model_file} --output-document=/workspace/assets/${model_file}
99

1010
# Python package versions
1111
ARG numpy_version=1.14.1
1212
ARG tf_version=1.5.0
1313
ARG keras_version=2.1.4
1414

15-
RUN pip install --upgrade pip && \
16-
pip install numpy==${numpy_version} && \
15+
RUN pip install numpy==${numpy_version} && \
1716
pip install tensorflow==${tf_version} && \
1817
pip install Pillow && \
1918
pip install h5py && \
20-
pip install keras==${keras_version} && \
21-
pip install flask-restplus && \
22-
pip install ipython
19+
pip install keras==${keras_version}
2320

2421
COPY . /workspace
2522

tests/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
import requests
3+
4+
5+
def test_response():
6+
model_endpoint = 'http://localhost:5000/model/predict'
7+
file_path = 'assets/cat.jpg'
8+
9+
with open(file_path, 'rb') as file:
10+
file_form = {'image': (file_path, file, 'image/jpeg')}
11+
r = requests.post(url=model_endpoint, files=file_form)
12+
13+
assert r.status_code == 200
14+
response = r.json()
15+
assert response['status'] == 'ok'
16+
assert response['predictions'][0]['label_id'] == 'n02123045'
17+
assert response['predictions'][0]['label'] == 'tabby'
18+
assert response['predictions'][0]['probability'] > 0.6
19+
20+
21+
if __name__ == '__main__':
22+
pytest.main([__file__])

0 commit comments

Comments
 (0)