首页 > 解决方案 > 在 sagemaker 中使用带有对象检测 API 的 tensorboard

问题描述

有了这个,我在 docker 容器中使用 Tensorflow 对象检测 API 在 sagemaker 上成功创建了一个培训作业。现在我想使用 sagemaker 监控培训工作,但找不到任何解释如何做到这一点的东西。我不使用 sagemaker 笔记本。我想我可以通过将日志保存到 S3 存储桶并指向本地 tensorboard 实例来做到这一点.. 但不知道如何告诉 tensorflow 对象检测 API 将日志保存在哪里(是否有任何命令行参数?)。像这样,但脚本generate_tensorboard_command.py失败,因为我的培训工作没有sagemaker_submit_directory参数..

事实是,当我开始培训工作时,我的 s3 上什么都没有创建,直到工作完成并上传所有内容。应该有一种方法告诉 tensorflow 在训练期间将日志(s3)保存在哪里,希望无需修改 API 源代码。

编辑

我终于可以让它与公认的解决方案一起工作(tensorflow本机支持读/写s3),但是还有其他步骤要做:

  1. 在训练作业配置中禁用网络隔离
  2. 向 docker 映像提供凭据以写入 S3 存储桶

唯一的问题是 Tensorflow 不断地轮询文件系统(即在服务模式下寻找更新的模型),这会导致对 S3 的无用请求,您将不得不付费(以及控制台中的大量错误)。为此,我在这里提出了一个新问题。至少它有效。

编辑 2

我错了,TF 只是写日志,不是轮询,所以这是一种预期的行为,额外的成本是最小的。

标签: object-detectiontensorboardamazon-sagemakerobject-detection-apitensorflow-model-garden

解决方案


查看您发布的示例,看起来好像model_dir传递给 TensorFlow 对象检测包的配置为/opt/ml/model

# These are the paths to where SageMaker mounts interesting things in your container.
prefix = '/opt/ml/'
input_path = os.path.join(prefix, 'input/data')
output_path = os.path.join(prefix, 'output')
model_path = os.path.join(prefix, 'model')
param_path = os.path.join(prefix, 'input/config/hyperparameters.json')

在训练过程中,tensorboard日志会被写入/opt/ml/model,然后上传到s3作为训练后的最终模型工件:https ://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-training-algo -envvariables.html

可能能够绕过 SageMaker 工件上传步骤,并model_dir在训练期间将 TensorFlow 对象检测 API 直接指向 s3 位置:

model_path = "s3://your-bucket/path/here

这意味着 SageMaker 作业中的 TensorFlow 库直接写入 S3,而不是其容器内的文件系统。假设底层 TensorFlow 对象检测代码可以直接写入 S3(您必须验证这一点),您应该能够实时查看 tensorboard 日志和检查点。


推荐阅读