2017-12-14 222 views

Trả lời

1

Dưới đây là cách bạn có thể hiển thị mô hình của mình trực tuyến trên Google Colab. Dưới đây là một ví dụ rất đơn giản hiển thị trình giữ chỗ:

from IPython.display import clear_output, Image, display, HTML 
import tensorflow as tf 
import numpy as np 
from google.colab import files 

def strip_consts(graph_def, max_const_size=32): 
    """Strip large constant values from graph_def.""" 
    strip_def = tf.GraphDef() 
    for n0 in graph_def.node: 
     n = strip_def.node.add() 
     n.MergeFrom(n0) 
     if n.op == 'Const': 
      tensor = n.attr['value'].tensor 
      size = len(tensor.tensor_content) 
      if size > max_const_size: 
       tensor.tensor_content = "<stripped %d bytes>"%size 
    return strip_def 

def show_graph(graph_def, max_const_size=32): 
    """Visualize TensorFlow graph.""" 
    if hasattr(graph_def, 'as_graph_def'): 
     graph_def = graph_def.as_graph_def() 
    strip_def = strip_consts(graph_def, max_const_size=max_const_size) 
    code = """ 
     <script> 
      function load() {{ 
      document.getElementById("{id}").pbtxt = {data}; 
      }} 
     </script> 
     <link rel="import" href="https://tensorboard.appspot.com/tf-graph-basic.build.html" onload=load()> 
     <div style="height:600px"> 
      <tf-graph-basic id="{id}"></tf-graph-basic> 
     </div> 
    """.format(data=repr(str(strip_def)), id='graph'+str(np.random.rand())) 

    iframe = """ 
     <iframe seamless style="width:1200px;height:620px;border:0" srcdoc="{}"></iframe> 
    """.format(code.replace('"', '&quot;')) 
    display(HTML(iframe)) 


"""Create a sample tensor""" 
sample_placeholder= tf.placeholder(dtype=tf.float32) 
"""Show it""" 
graph_def = tf.get_default_graph().as_graph_def() 
show_graph(graph_def) 

Hiện tại, bạn không thể chạy dịch vụ Tensorboard trên Google Colab theo cách bạn chạy cục bộ. Ngoài ra, bạn không thể xuất toàn bộ nhật ký của mình sang Drive thông qua một cái gì đó như summary_writer = tf.summary.FileWriter('./logs', graph_def=sess.graph_def) để sau đó bạn có thể tải xuống và xem nó cục bộ.

9

Tôi hiện đang sử dụng ngrok để lưu lượng truy cập đường hầm vào máy chủ cục bộ.
Ví dụ về colab có thể được tìm thấy here.

Đây là những bước (các đoạn mã đại diện cho các tế bào của loại "code" trong colab):

  1. Nhận TensorBoard chạy ở chế độ nền.
    Lấy cảm hứng từ this answer.

    LOG_DIR = '/tmp/log' 
    get_ipython().system_raw(
        'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &' 
        .format(LOG_DIR) 
    ) 
    
  2. Tải về và giải nén ngrok.
    Thay thế liên kết được chuyển đến wget bằng liên kết tải xuống chính xác cho Hệ điều hành của bạn.

    ! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip 
    ! unzip ngrok-stable-linux-amd64.zip 
    
  3. quá trình nền Launch ngrok ...

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

    ... và lấy url công cộng. Source

    ! curl -s http://localhost:4040/api/tunnels | python3 -c \ 
        "import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])" 
    
Các vấn đề liên quan