Skip to content

Instantly share code, notes, and snippets.

@metal3d
Created September 10, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metal3d/f94b8fa12499344957e7af60f17a8192 to your computer and use it in GitHub Desktop.
Save metal3d/f94b8fa12499344957e7af60f17a8192 to your computer and use it in GitHub Desktop.
Simple Keras model loader and prediction handler for Nuclio
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"
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