首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Google Cloud Platform和AI平台提供预测服务

使用Google Cloud Platform和AI平台提供预测服务
EN

Stack Overflow用户
提问于 2019-09-06 16:22:13
回答 1查看 88关注 0票数 0

我在tensorflow的帮助下训练了一个AI模型,需要使用Google AI平台来提供预测服务。

现在AI平台指定模型需要是特定的'SavedModel‘格式,以便我将模型上传到云并提供预测。

如何将模型转换为指定的'SavedModel‘格式?

另外,有没有端到端的教程可以帮助我做同样的事情?

EN

回答 1

Stack Overflow用户

发布于 2020-11-05 16:23:45

在一个标准的训练循环中,最后应该有如下代码

代码语言:javascript
运行
复制
.....
def train_and_evaluate(output_dir, hparams):
    get_train = read_dataset(hparams['train_data_path'],
                             tf.estimator.ModeKeys.TRAIN,
                             hparams['train_batch_size'])
    get_valid = read_dataset(hparams['eval_data_path'],
                             tf.estimator.ModeKeys.EVAL,
                             1000)
    estimator = tf.estimator.Estimator(model_fn=sequence_regressor,
                                       params=hparams,
                                       config=tf.estimator.RunConfig(
                                           save_checkpoints_steps=
                                           hparams['save_checkpoint_steps']),
                                       model_dir=output_dir)
    train_spec = tf.estimator.TrainSpec(input_fn=get_train,
                                        max_steps=hparams['train_steps'])
    exporter = tf.estimator.LatestExporter('exporter', serving_input_fn)
    eval_spec = tf.estimator.EvalSpec(input_fn=get_valid,
                                      steps=None,
                                      exporters=exporter,
                                      start_delay_secs=hparams['eval_delay_secs'],
                                      throttle_secs=hparams['min_eval_frequency'])
    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

尤其是这部分

代码语言:javascript
运行
复制
estimator = tf.estimator.Estimator(model_fn=sequence_regressor,
                                       params=hparams,
                                       config=tf.estimator.RunConfig(
                                           save_checkpoints_steps=
                                           hparams['save_checkpoint_steps']),
                                       model_dir=output_dir)

在此指定将模型导出到output_dir的步数(save_checkpoints_steps)。

你的代码中有类似这样的东西吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57818293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档