简体   繁体   English

在Google Cloud上的Docker上查看Tensorboard

[英]View Tensorboard on Docker on Google Cloud

I am trying to display TensorBoard from TensorFlow on Docker on Google Cloud. 我正在尝试在Google Cloud上的Docker上显示TensorFlow的TensorBoard。

http://tensorflow.org/how_tos/summaries_and_tensorboard/index.md http://tensorflow.org/how_tos/summaries_and_tensorboard/index.md

tensorboard --logdir ./

I have Apache running on Google Cloud (it may be in my first container "ai-unicorn" Docker made its own container "docker-playground"). 我在Apache Cloud上运行了Apache(它可能是在我的第一个容器“ ai-unicorn”中,Docker使其成为了自己的容器“ docker-playground”)。 I can see the default page from Google Cloud at http://104.197.119.57/ . 我可以从http://104.197.119.57/看到Google Cloud的默认页面。

I start TensorBoard on Google Cloud like this: 我像这样在Google Cloud上启动TensorBoard:

root@6cf64fd299f0:/# tensorboard --logdir ./ Starting TensorBoard on port 6006 (You can navigate to http://localhost:6006)

I tried the Google Cloud SSH option called "Open in browser window on custom port" using port 6006. 我尝试使用端口6006调用名为“在自定义端口的浏览器窗口中打开”的Google Cloud SSH选项。

It displays: "We are unable to connect to the VM on port 6006." 它显示:“我们无法在端口6006上连接到VM。”

What is the correct way to view TensorBoard from Google Cloud? 从Google Cloud查看TensorBoard的正确方法是什么?

By default , TensorBoard serves requests on 127.0.0.1 , which is only accessible to processes running on the same machine. 默认情况下 ,TensorBoard在127.0.0.1上提供请求,只有在同一台计算机上运行的进程才能访问该请求。 If you start TensorBoard with --host 0.0.0.0 , it will also serve requests on the remote interfaces, so you should be able to connect to it remotely: 如果您使用--host 0.0.0.0启动TensorBoard,它还将在远程接口上处理请求,因此您应该可以远程连接到它:

$ tensorboard --logdir ./ --host 0.0.0.0

Note that the "Open in browser window on custom port" will not connect you to the TensorBoard server - this option is used to connect to an SSH server on a non-standard port. 请注意,“在自定义端口上的浏览器窗口中打开”将不会将您连接到TensorBoard服务器-此选项用于在非标准端口上连接到SSH服务器。 The Google Cloud Platform docs have information on how to expose ports from your VM. Google Cloud Platform文档包含有关如何从VM公开端口的信息。 You will need to allow connections on TCP port 6006 for remote access to your VM. 您将需要允许TCP端口6006上的连接以远程访问您的VM。 You may also need to expose port 6006 from your Docker container, by following the instructions here . 您可能还需要按照此处说明从Docker容器中公开端口6006。

EDIT: Added some step-by-step instructions to help with your Docker configuration. 编辑:添加了一些分步说明来帮助您配置Docker。 There are several issues here, and it's not possible to tell which one is failing. 这里有几个问题,无法确定哪个是失败的。

  1. Configure port forwarding when you start your Docker container: 在启动Docker容器时配置端口转发:

     (vm)$ docker run -p 0.0.0.0:7007:6006 -it b.gcr.io/tensorflow/tensorflow 

    This forwards connections from port 7007 on your VM to 6006 in your Docker container. 这会将连接从VM上的端口7007转发到Docker容器中的6006。 (Other values are possible.) (其他值是可能的。)

  2. Ensure that you can connect to TensorBoard from within the Docker container: 确保您可以从Docker容器中连接到TensorBoard:

     (container)$ tensorboard --logdir ./ --host 0.0.0.0 --port 6006 & (container)$ curl http://localhost:6006/ 

    The second command should print some HTML to the console. 第二个命令应将一些HTML打印到控制台。

  3. In a shell on the VM, ensure that you can connect to the TensorBoard instance running in the container: 在VM上的外壳中,确保可以连接到在容器中运行的TensorBoard实例:

     (vm)$ curl http://localhost:7007/ 

    The command should print the same HTML to the console. 该命令应将相同的HTML打印到控制台。

  4. Configure the Google Cloud firewall to allow your local client to connect to port 7007 on your VM. 配置Google Cloud防火墙,以允许本地客户端连接到VM上的端口7007。

     (client)$ gcloud compute firewall-rules create tensorboard --allow tcp:7007 

    You should now be able to connect to TensorBoard in a web browser on your client. 您现在应该可以在客户端的Web浏览器中连接到TensorBoard。

You do not have to use Docker to display the TensorBoard. 您不必使用Docker来显示TensorBoard。 But if you do want to use Docker, just run the TensorBoard inside of your Docker image. 但是,如果您确实想使用Docker,只需在Docker映像内运行TensorBoard。

The trick is to allow external access to the default TensorBoard tcp port 6006. 诀窍是允许外部访问默认的TensorBoard tcp端口6006。

I tried the following working solution to display TensorBoard in my Google Cloud VM. 我尝试了以下工作解决方案以在我的Google Cloud VM中显示TensorBoard。

  1. ensure you pass the gcloud authentication: 确保您通过了gcloud身份验证:

    gcloud auth login gcloud身份验证登录

  2. allow public access to the tcp port 6006 允许公共访问tcp端口6006

    gcloud compute firewall-rules create tensorboard-port --allow tcp:6006 gcloud计算防火墙规则创建tensorboard-port --allow tcp:6006

  3. Run TensorBoard on your VM 在您的VM上运行TensorBoard

    tensorboard --logdir=workspace/train/ 张量板--logdir = workspace / train /

  4. Use external IP address to access the TensorBoard outside your VM: 使用外部IP地址访问VM外部的TensorBoard:

    Open address http://your_vm_external IP:6006/, 打开地址http:// your_vm_external IP:6006 /,

    eg http://104.196.140.145:6006/ , where 104.196.140.145 is the external IP address of my VM. 例如http://104.196.140.145:6006/ ,其中104.196.140.145是我的VM的外部IP地址。

享受TensorBoard

another option is to use ngrok to tunnel. 另一个选择是使用ngrok进行隧道传输。 see: Can I use Tensorboard with Google Colab? 请参阅: 我可以将Tensorboard与Google Colab一起使用吗?

$ from jupyter notebook
ps = !ps -ax
is_tensorboard_running = len([f for f in ps if "tensorboard" in f ]) > 0

is_ngrok_running = len([f for f in ps if "ngrok" in f ]) > 0
print("tensorbord={}, ngrok={}".format(is_tensorboard_running, is_ngrok_running))

if not is_ngrok_running:  
#    grok should be installed in /content/ngrok
  get_ipython().system_raw('/content/ngrok http 6006 &')
  is_ngrok_running = True

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM