首页 > 解决方案 > 如何在谷歌云平台上使用带有 tf.estimator 的 datalab 的 tensorboard 调试器

问题描述

当我通过 datalab 启动 tensorboard 时,它使用此处描述的 google 语法。本文档仅提及开始、停止和列表。但是,有一个我无法使用的调试器窗格。

文档描述了如何将 tensorboard 调试器与 tf.estimator 一起使用,但它使用了不同的语法。

有没有办法将两者混合在一起,以便调试器可以与 datalab 一起使用?

标签: tensorflowgoogle-cloud-platformtensorboardgoogle-cloud-datalab

解决方案


我认为您不能在 datalab 中运行 tfdbg。您可以使用本指南获取代码并在控制台上运行它:

  1. 我正在使用使用 model.py 和 task.py 的 datalab 笔记本。我的代码最初是根据这个文件建模的。

  2. model.py如上面提到的指南中所示,对代码进行此更改。

    from tensorflow.python import debug as tf_debug
    # for debugging
    hooks = [tf_debug.LocalCLIDebugHook()]
    

然后在train_and_evaluate(args)例程中添加对调用的参数列表中的挂钩的引用EvalSpec()。像这样:

    # .. also need an EvalSpec which controls the evaluation and
    # the checkpointing of the model since they happen at the same time
    eval_spec = tf.estimator.EvalSpec(
        input_fn = read_dataset(
            args['eval_data_paths'],
            batch_size = 10000,  # original 10000
            mode = tf.estimator.ModeKeys.EVAL),
        steps=None, # evals on 100 batches
        start_delay_secs = args['eval_delay_secs'], # start evaluating after N secoonds. 
        throttle_secs = args['min_eval_frequency'], # eval no more than every N seconds.
        exporters = exporter,# how to export the model for production.
        hooks = hooks) # for the debugger 

然后使用您喜欢的虚拟 python 环境,执行以下操作:(我正在使用 anaconda)

  1. 用anaconda打开python 2.7环境

    $ . ~/bin/setenv-anaconda2.sh
    
  2. 激活tensorflow python2.7 anaconda环境

    $ conda activate tensorflow
    
  3. 获取 gcloud 环境

    $ . ~/progs/datalab-notebooks/bin/setenv_google.sh
    
  4. 对于这个模型,设置一个 python 路径来查找模块

    cd ~/progs/datalab-notebooks/tf-debug
    export PYTHONPATH=${PYTHONPATH}:${PWD}/taxisimple
    

然后训练:--train_steps=1000。似乎是最大步数。

python -m trainer.task \
   --train_data_paths="${PWD}/taxi-train*" \
   --eval_data_paths=${PWD}/taxi-valid.csv  \
   --output_dir=${PWD}/taxi_trained \
   --train_steps=1000 --job-dir=./tmp

这会给你一个 tftdbg 提示。从这里您可以使用 tfdbg 探索模型。


推荐阅读