Created
September 10, 2018 11:47
-
-
Save metal3d/f94b8fa12499344957e7af60f17a8192 to your computer and use it in GitHub Desktop.
Simple Keras model loader and prediction handler for Nuclio
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
apiVersion: "nuclio.io/v1beta1" | |
kind: "Function" | |
spec: | |
runtime: "python:3.6" | |
handler: main:handler | |
minReplicas: 1 | |
maxReplicas: 1 | |
build: | |
baseImage: python:3.6-jessie | |
commands: | |
- "apt-get update && apt-get install -y wget" | |
- "pip install keras tensorflow numpy" |
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
import keras | |
import json | |
def handler(context, event): | |
""" Not fully tested, | |
but this is a nice way to get keras inference with Nuclio """ | |
data = json.loads(event.body.decode('utf-8')) | |
model = load_model('my_model.h5') | |
pred = model.predict(data) | |
context.Response(body=json.dumps(pred), | |
headers={}, | |
content_type='application/json', | |
status_code=200) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment