首页 > 解决方案 > 如何加载保存的 DNN 估计器模型进行预测?

问题描述

我有一个保存的 DNN 估计器模型。如何恢复模型进行预测?我使用以下方法保存了我的模型:

#Create the input function
input_func = tf.estimator.inputs.pandas_input_fn(x=X_train, y=y_train, batch_size=100, num_epochs=None, shuffle=True)

#Create the model
model = tf.estimator.DNNClassifier(feature_columns=feat_cols, hidden_units=[10, 10], n_classes=2, model_dir=model_path)

所以,在 model_path 目录中,我有:

  • 检查点
  • 事件.out.tf...
  • 图.pbtxt
  • 模型.ckpt-1...
  • 模型.ckpt-1...
  • 模型.ckpt-1...
  • 型号.ckpt-5000...
  • 型号.ckpt-5000...
  • 型号.ckpt-5000...

任何想法?

标签: pythontensorflowmodelrestoretensorflow-estimator

解决方案


也许您可以尝试如下预测器

from tensorflow.contrib import predictor

my_predict = predictor.from_saved_model(model_path)
prediction = my_predict({"x": [your_testing_data]})

希望这可以帮助!


推荐阅读