Created
August 14, 2019 19:22
-
-
Save zmjjmz/048968f9149fcd0c03b657260751f978 to your computer and use it in GitHub Desktop.
Vespa Keras weirdness
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 numpy as np | |
input_l = keras.Input(shape=(1,), name='input') | |
layer_1 = keras.layers.Dense(1, activation='relu', name='layer_1')(input_l) | |
output_l = keras.layers.Dense(1, activation='linear', name='output')(layer_1) | |
model = keras.Model(inputs=[input_l], outputs=[output_l]) | |
model.compile(loss='mean_absolute_error', optimizer='rmsprop') | |
x = np.array(np.arange(1, 100000)) | |
y = np.array(np.arange(1, 100000)) | |
model.fit(np.array(x).reshape(-1),np.array(y), epochs=2, shuffle=False, batch_size=100) | |
from keras import backend as K | |
import tensorflow as tf | |
print("TF Version: {0}".format(tf.VERSION)) | |
keras.backend.get_session().run(tf.global_variables_initializer()) | |
signature = tf.saved_model.signature_def_utils.predict_signature_def( | |
inputs={'userid': model.input}, outputs={'scores': model.output}) | |
builder = tf.saved_model.builder.SavedModelBuilder('func_model') | |
builder.add_meta_graph_and_variables( | |
sess=K.get_session(), | |
tags=[tf.saved_model.tag_constants.SERVING], | |
signature_def_map={ | |
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: | |
signature | |
}) | |
builder.save() |
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
$ saved_model_cli show --dir func_model/ --all | |
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: | |
signature_def['serving_default']: | |
The given SavedModel SignatureDef contains the following input(s): | |
inputs['userid'] tensor_info: | |
dtype: DT_FLOAT | |
shape: (-1, 1) | |
name: input:0 | |
The given SavedModel SignatureDef contains the following output(s): | |
outputs['scores'] tensor_info: | |
dtype: DT_FLOAT | |
shape: (-1, 1) | |
name: output/BiasAdd:0 | |
Method name is: tensorflow/serving/predict |
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 tensorflow as tf | |
import numpy as np | |
input_l = tf.keras.Input(shape=(1,), name='input') | |
layer_1 = tf.keras.layers.Dense(1, activation='relu', name='layer_1')(input_l) | |
output_l = tf.keras.layers.Dense(1, activation='linear', name='output')(layer_1) | |
model = tf.keras.Model(inputs=[input_l], outputs=[output_l]) | |
model.compile(loss='mean_absolute_error', optimizer='rmsprop') | |
x = np.array(np.arange(1, 100000)) | |
y = np.array(np.arange(1, 100000)) | |
model.fit(np.array(x).reshape(-1),np.array(y), epochs=2, shuffle=False, batch_size=100) | |
print("TF Version: {0}".format(tf.VERSION)) | |
tf.keras.backend.get_session().run(tf.global_variables_initializer()) | |
signature = tf.saved_model.signature_def_utils.predict_signature_def( | |
inputs={'userid': model.input}, outputs={'scores': model.output}) | |
builder = tf.saved_model.builder.SavedModelBuilder('tfkeras_model') | |
builder.add_meta_graph_and_variables( | |
sess=tf.keras.backend.get_session(), | |
tags=[tf.saved_model.tag_constants.SERVING], | |
signature_def_map={ | |
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: | |
signature | |
}) | |
builder.save() |
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
$ saved_model_cli show --dir tfkeras_model/ --all | |
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs: | |
signature_def['serving_default']: | |
The given SavedModel SignatureDef contains the following input(s): | |
inputs['userid'] tensor_info: | |
dtype: DT_FLOAT | |
shape: (-1, 1) | |
name: input:0 | |
The given SavedModel SignatureDef contains the following output(s): | |
outputs['scores'] tensor_info: | |
dtype: DT_FLOAT | |
shape: (-1, 1) | |
name: output/BiasAdd:0 | |
Method name is: tensorflow/serving/predict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment