2017-12-14 17 views

答えて

1

Google Colabでモデルをインラインで表示する方法は次のとおりです。以下は、プレースホルダを表示する非常に単純な例です:現在

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) 

は、Googleコラボにあなたがローカルで実行する方法をTensorboardサービスを実行することはできません。また、ログ全体をドライブにエクスポートすることはできません(summary_writer = tf.summary.FileWriter('./logs', graph_def=sess.graph_def)など)ので、ダウンロードしてローカルで見ることができます。

9

私は現在、ローカルホストへのトラフィックをトンネルするためにngrokを使用しています。
コラブの例はhereです。

  1. TensorBoardがバックグラウンドで実行して取得:

    これらは、ステップ(コードスニペットはコラボの「コード」タイプの細胞を表す)です。
    this answerからインスパイアされます。

    LOG_DIR = '/tmp/log' 
    get_ipython().system_raw(
        'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &' 
        .format(LOG_DIR) 
    ) 
    
  2. ダウンロードとngrokを解凍します。
    wgetに渡されたリンクを、お使いのOSに適したダウンロードリンクに置き換えてください。

    ! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip 
    ! unzip ngrok-stable-linux-amd64.zip 
    
  3. 起動ngrokバックグラウンド・プロセス ...

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

    ...と公開URLを取得します。 Source

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