Last active
April 3, 2020 09:42
-
-
Save alvarolopez/850160d4681794d5292222d4ebbaf938 to your computer and use it in GitHub Desktop.
IRIS and DEEPaaS integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ virtualenv env --python=python3 | |
(...) | |
$ source env/bin/activate | |
(env) $ pip3 install . | |
(...) | |
(env) $ pip3 install deepaas | |
(...) | |
(env) $ deepaas-run | |
## ### | |
## ###### ## | |
.##### ##### #######. .#####. | |
## ## ## // ## // ## ## ## | |
##. .## ### ### // ### ## ## | |
## ## #### #### #####. | |
Hybrid-DataCloud ## | |
Welcome to the DEEPaaS API API endpoint. You can directly browse to the | |
API documentation endpoint to check the API using the builtint Swagger UI | |
or you can use any of our endpoints. | |
API documentation: http://127.0.0.1:5000/ui | |
API specification: http://127.0.0.1:5000/swagger.json | |
V2 endpoint: http://127.0.0.1:5000/v2 | |
------------------------------------------------------------------------- | |
2020-02-04 13:10:50.027 21186 INFO deepaas [-] Starting DEEPaaS version 1.0.0 | |
2020-02-04 13:10:50.231 21186 INFO deepaas.api [-] Serving loaded V2 models: ['iris-deepaas'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from joblib import dump, load | |
import numpy | |
from sklearn import svm | |
from sklearn import datasets | |
from webargs import fields, validate | |
def train(): | |
clf = svm.SVC() | |
X, y = datasets.load_iris(return_X_y=True) | |
clf.fit(X, y) | |
dump(clf, 'iris.joblib') | |
def predict(data): | |
clf = load('iris.joblib') | |
data = numpy.array(data).reshape(1, -1) | |
prediction = clf.predict(data) | |
return {"labels": prediction.tolist()} | |
def get_predict_args(): | |
args = { | |
"data": fields.List( | |
fields.Float(), | |
required=True, | |
description="Data to make a prediction. The IRIS dataset expects " | |
"four values containing the Sepal Length, Sepal Width, " | |
"Petal Length and Petal Width.", | |
validate=validate.Length(equal=4), | |
), | |
} | |
return args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from joblib import dump, load | |
import numpy | |
from sklearn import svm | |
from sklearn import datasets | |
def train(): | |
clf = svm.SVC() | |
X, y = datasets.load_iris(return_X_y=True) | |
clf.fit(X, y) | |
dump(clf, 'iris.joblib') | |
def predict(data): | |
clf = load('iris.joblib') | |
data = numpy.array(data).reshape(1, -1) | |
prediction = clf.predict(data) | |
return {"labels": prediction.tolist()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from distutils.core import setup | |
setup( | |
name='test-iris-with-deepaas', | |
version='1.0', | |
description='This is an SVM trained with the IRIS dataset', | |
author='Álvaro López', | |
author_email='aloga@ifca.unican.es', | |
py_modules="iris-deepaas.py", | |
dependencies=['joblib', 'scikit-learn'], | |
entry_points={ | |
'deepaas.v2.model': ['iris=iris-deepaas'], | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment