亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用“預測”Sgature Def 在 Java 中加載 Tensorflow

如何使用“預測”Sgature Def 在 Java 中加載 Tensorflow

茅侃侃 2023-07-28 09:59:09
我正在訓練 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”


查看完整回答
反對 回復 2023-07-28
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號