【问题标题】:Serving Predictions with Google Cloud Platform and AI Platform使用 Google Cloud Platform 和 AI Platform 提供预测服务
【发布时间】:2020-11-05 16:23:45
【问题描述】:

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

现在 AI Platform 指定模型需要采用特定的“SavedModel”格式,以便我将模型上传到云端并提供预测。

如何将模型转换为指定的“SavedModel”格式?

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

【问题讨论】:

  • 定义模型时,必须定义导出器。这个导出器大多数时候是一个存储桶。你有这个吗?
  • 如果您需要更具体的帮助,请发布您现在保存的方式。
  • 我能问你@guillaumeblaquiere,你在哪里定义了这样一个出口商?在管道配置文件中?
  • 使用 tensorflow,您可以在训练循环中使用它。但是你没有提到你使用 tensorflow。你为什么要谈论管道?您能否通过代码示例准确说明您的问题/上下文?

标签: google-cloud-platform google-cloud-ml


【解决方案1】:

在标准的训练循环中,最后应该有这样的代码

.....
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)

尤其是这部分

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)

您可以在此处指定在多少步 (save_checkpoints_steps) 之后将模型导出到 output_dir

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

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 1970-01-01
    • 2021-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 2020-09-02
    相关资源
    最近更新 更多