Skip to content

Commit

Permalink
update requests params and install from requirements.txt (#15)
Browse files Browse the repository at this point in the history
resolves #8, resolves #9
  • Loading branch information
bdwyer2 authored Sep 13, 2018
1 parent f1b3cb3 commit a0d2a28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Dockerfile
README.*
docs/
.git/
Expand Down
17 changes: 2 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@ RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-
RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-api.us-geo.objectstorage.softlayer.net/audioset/vggish_pca_params.npz && mv vggish_pca_params.npz /workspace/assets/
RUN wget -nv --show-progress --progress=bar:force:noscroll http://max-assets.s3-api.us-geo.objectstorage.softlayer.net/audioset/classifier_model.h5 && mv classifier_model.h5 /workspace/assets/

# Python package versions
ARG numpy_version=1.13.1
ARG tf_version=1.8.0
ARG scipy_version=0.19.1
ARG six_version=1.10.0

RUN pip install numpy==${numpy_version} && \
pip install tensorflow==${tf_version} && \
pip install scipy==${scipy_version} && \
pip install resampy && \
pip install six==${six_version} && \
pip install pandas && \
pip install keras && \
pip install h5py && \
pip install json_tricks
COPY requirements.txt /workspace
RUN pip install -r requirements.txt

COPY . /workspace

Expand Down
18 changes: 8 additions & 10 deletions api/model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from flask_restplus import Namespace, Resource, fields
from werkzeug.datastructures import FileStorage
from werkzeug.exceptions import BadRequest

from config import MODEL_META_DATA

from core.backend import ModelWrapper
import os
import numpy as np
import pandas as pd

api = Namespace('model', description='Model information and inference operations')

Expand All @@ -27,20 +23,22 @@ def get(self):
"""Return the metadata associated with the model"""
return MODEL_META_DATA


label_prediction = api.model('LabelPrediction', {
'label_id': fields.String(required=False, description='Label identifier'),
'label': fields.String(required=True, description='Class label'),
'label': fields.String(required=True, description='Audio class label'),
'probability': fields.Float(required=True)
})

predict_response = api.model('ModelPredictResponse', {
'status': fields.String(required=True, description='Response status message'),
'predictions': fields.List(fields.Nested(label_prediction), description='Predicted labels and probabilities')
'predictions': fields.List(fields.Nested(label_prediction), description='Predicted audio classes and probabilities')
})

# set up parser for audio input data
audio_parser = api.parser()
audio_parser.add_argument('audio', type=FileStorage, location='files', required=True)
audio_parser.add_argument('audio', type=FileStorage, location='files', required=True,
help="signed 16-bit PCM WAV audio file")


@api.route('/predict')
Expand All @@ -61,7 +59,7 @@ def post(self):
if os.path.exists("/audio.wav"):
os.remove("/audio.wav")

if('.wav' in str(args['audio'])):
if '.wav' in str(args['audio']):
file = open("/audio.wav", "wb")
file.write(audio_data)
file.close()
Expand All @@ -70,10 +68,10 @@ def post(self):
e.data = {'status': 'error', 'message': 'Invalid file type/extension'}
raise e

#Getting the predicions
# Getting the predictions
preds = self.mw.predict("/audio.wav")

#Aligning the predictions to the required API format
# Aligning the predictions to the required API format
label_preds = [{'label_id': p[0], 'label': p[1], 'probability': p[2]} for p in preds]
result['predictions'] = label_preds
result['status'] = 'ok'
Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
numpy==1.13.1
tensorflow==1.8.0
scipy==0.19.1
resampy
six==1.10.0
pandas
keras
h5py

0 comments on commit a0d2a28

Please sign in to comment.