python - How to export VocabularyProcessor and use it after TF serve loading? -
i have 2 parts of code:
- script training data (python+tf+bag_of_words)
- script predict class of string (now python, later golang in production)
i going train model @ python , use model in production through golang api.
training steps:
- fit
tf.contrib.learn.preprocessing.vocabularyprocessor - train bow algorithm
- add output
tf.estimator.export.classificationoutput - add input
tf.estimator.export.servinginputreceiver - export
tf.estimator.estimatorexport_savedmodel
it works fine, want proxy client model string. , string should converted vector through vocabularyprocessor. vocabularyprocessor not tensor , can not use graph node. , can not pickle because not restore golang client implementation.
is possible resolve question?
def preprocess_for_prediction(n_words): def serving_input_fn(): words = tf.placeholder(dtype=tf.string) receiver_inputs = {"raw_words": words} # use const needed convert raw_words vector vector = tf.constant([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], shape=(1, 10), dtype=tf.int32) features = {words_feature: vector} return tf.estimator.export.servinginputreceiver(features, receiver_inputs) return serving_input_fn upd:
i read tensorflow-transform. think work me, after trying write answer here.
Comments
Post a Comment