如何在Tensorflow版本中保存和加载tf.estimator.BoostedTreesRegressor模型='2.0.0'

问题描述 投票:0回答:1

我是tf.estimator.BoostedTreesRegressor的新手。这是我用来构建模型的示例代码。

n_batches = 20

est = tf.estimator.BoostedTreesRegressor(feature_columns,
                                           n_batches_per_layer=n_batches , learning_rate=0.001, n_trees=700,
                                            max_depth=13, 
model_dir = "model", tf.config.threading.set_intra_op_parallelism_threads(60))

est.train(train_input_fn, max_steps=10)

我要保存模型..然后加载模型以预测销售。

您能否在TensorFlow版本2中帮助我,因为我找不到...

谢谢

tensorflow tensorflow-estimator
1个回答
0
投票

您的模型应该根据官方的model_dir保存在documentation路径中。实例化BoostedTreesRegressor时,请指定model_dir的真实目录路径。

此外,您可以使用export_saved_model方法保存模型。

# Saving estimator model
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
  tf.feature_column.make_parse_example_spec(feature_columns))
export_path = estimator.export_saved_model("/dir/path/", serving_input_fn)

对于加载保存的模型,您可以如下使用saved_model.load功能:

#loading saved model
imported = tf.saved_model.load(export_path)
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.