Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.