2017-12-14 189 views

cevap

1

Modellerinizi Google Colab'da satır içi olarak nasıl görüntüleyebilirsiniz.

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) 

Şu anda yerel olarak çalıştırmak yolu, Google CoLab bir Tensorboard hizmetini koşamam: Aşağıda yer tutucu görüntüler çok basit bir örnektir. Ayrıca, tüm günlüğünüzü summary_writer = tf.summary.FileWriter('./logs', graph_def=sess.graph_def) gibi bir şeyle Drive'ınıza dışa aktaramazsınız, böylece yerel olarak indirebilirsiniz ve indirebilirsiniz.

9

Şu anda localhost'a tünel trafiği yapmak için ngrok kullanıyorum.
Bir colab örneği here bulunabilir.

  1. alın TensorBoard arka planda çalışan:

    Bunlar

    adımlar (kod parçalarını CoLab tip "kod" hücrelerini temsil) bulunmaktadır.
    this answer'den esinlenmiştir.

    LOG_DIR = '/tmp/log' 
    get_ipython().system_raw(
        'tensorboard --logdir {} --host 0.0.0.0 --port 6006 &' 
        .format(LOG_DIR) 
    ) 
    
  2. İndirme ve ngrok halletmek.
    wget'a iletilen bağlantıyı, işletim sisteminiz için doğru karşıdan yükleme linkiyle değiştirin.

    ! wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip 
    ! unzip ngrok-stable-linux-amd64.zip 
    
  3. lansmanın ngrok arka plan işlemi ...

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

    ... ve kamu url almak. Source

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