我正在訓練 Tensorflow Estimator 并用于export_saved_model以 SavedModel 格式保存模型?,F在我想用 Tensorflow Java API 加載這個模型(我不想使用模型服務器,我需要直接用 Java 加載它)?,F在的問題是,Estimator.export_saved_model僅導出“predict”signature_def,而SavedModelBundleJava中的似乎僅支持具有“serving_default”簽名def的模型。所以問題是:有沒有辦法Estimator.export_saved_model包含“serving_default”簽名 def?或者是否可以使用 java 中的“預測”簽名 def 加載模型?或者還有其他我可以嘗試的選擇嗎?這是導出模型的代碼:feature_cols = [ tf.feature_column.numeric_column('numeric_feature'), tf.feature_column.indicator_column( tf.feature_column.categorical_column_with_vocabulary_list('categorial_text_feature', vocabulary_list=['WORD1', 'WORD1']))]estimator = tf.estimator.LinearRegressor( feature_columns=feature_cols, model_dir=model_dir, label_dimension=1) estimator.train(input_fn=input_fn)serving_input_receiver_fn = tf.estimator.export.build_raw_serving_input_receiver_fn({ 'numeric_feature': tf.placeholder(tf.float32, shape=(None,)), 'categorial_text_feature': tf.placeholder(tf.string, shape=(None,))})estimator.export_saved_model( export_dir_base=model_dir, serving_input_receiver_fn=serving_input_receiver_fn)如果我檢查模型,saved_model_cli show --tag_set serve我會得到:The given SavedModel MetaGraphDef contains SignatureDefs with the following keys:SignatureDef key: "predict"并與saved_model_cli show --tag_set serve --signature_def predict:The given SavedModel SignatureDef contains the following input(s): inputs['numeric_feature'] tensor_info: dtype: DT_FLOAT shape: (-1) name: Placeholder:0 inputs['categorial_text_feature'] tensor_info: dtype: DT_STRING shape: (-1) name: Placeholder_1:0The given SavedModel SignatureDef contains the following output(s): outputs['predictions'] tensor_info: dtype: DT_FLOAT shape: (-1) name: linear/linear_model/linear_model/linear_model/weighted_sum:0Method name is: tensorflow/serving/predict
1 回答

慕田峪7331174
TA貢獻1828條經驗 獲得超13個贊
找到了一個(不完美,但簡單)的解決方法:
我剛剛導出模型as_text=True
:
estimator.export_saved_model( export_dir_base=model_dir, serving_input_receiver_fn=serving_input_receiver_fn, as_text=True)
然后手動更改 .pbtxt 文件,使簽名 def 稱為“serving_default”
添加回答
舉報
0/150
提交
取消