Skip to content

Commit

Permalink
fixed all the issues with QuickStart tutorial doc, now it works
Browse files Browse the repository at this point in the history
  • Loading branch information
PycT committed Apr 12, 2019
1 parent 7a7f0f5 commit 601d8be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/src/main/paradox/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,24 @@ of your model and return your predictions.

```python
import numpy as np
import tensorflow as tf
import hydro_serving_grpc as hs
from keras.models import load_model

# 0. Load model once
model = load_model('/model/files/model.h5')

global graph
graph = tf.get_default_graph() #this is a workaround of keras' issue with multithreading

def infer(x):
# 1. Retrieve tensor's content and put it to numpy array
data = np.array(x.double_val)
data = data.reshape([dim.size for dim in x.tensor_shape.dim])

# 2. Make a prediction
result = model.predict(data)
with graph.as_default():
result = model.predict(data)

# 3. Pack the answer
y_shape = hs.TensorShapeProto(dim=[hs.TensorShapeProto.Dim(size=-1)])
Expand Down Expand Up @@ -169,7 +174,7 @@ install-command: "pip install -r requirements.txt"
payload:
- "src/"
- "requirements.txt"
- "model.h5"
- "linear_regression/model.h5"

contract:
name: infer
Expand Down

0 comments on commit 601d8be

Please sign in to comment.