且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以将TensorBoard与Google Colab一起使用吗?

更新时间:2022-06-25 23:57:08

编辑:您可能想给官方

You probably want to give the official %tensorboard magic a go, available from TensorFlow 1.13 onward.

%tensorboard魔法存在之前,标准方法 实现此目的是使用以下方式将网络流量代理到Colab VM ngrok .可以在此处.

Prior to the existence of the %tensorboard magic, the standard way to achieve this was to proxy network traffic to the Colab VM using ngrok. A Colab example can be found here.

这些是步骤(代码段代表colab中类型为代码"的单元格):

These are the steps (the code snippets represent cells of type "code" in colab):

  1. 使TensorBoard在后台运行.
    灵感来自此答案.

  1. Get TensorBoard running in the background.
    Inspired by this answer.

LOG_DIR = '/tmp/log'
get_ipython().system_raw(
    'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &'
    .format(LOG_DIR)
)

  • 下载并解压缩ngrok .
    用适合您操作系统的正确下载链接替换传递给wget的链接.

  • Download and unzip ngrok.
    Replace the link passed to wget with the correct download link for your OS.

    ! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
    ! unzip ngrok-stable-linux-amd64.zip
    

  • 启动ngrok后台进程...

  • Launch ngrok background process...

    get_ipython().system_raw('./ngrok http 6006 &')
    

    ...并检索公共网址. 来源

    ...and retrieve public url. Source

    ! curl -s http://localhost:4040/api/tunnels | python3 -c \
        "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"