让tensorboard与keras一起工作

时间:2018-01-16 13:27:41

标签: tensorflow deep-learning keras tensorboard keras-2

我有一个似乎在Keras没有直接解决方案的问题。我的服务器在ubuntu 14.04上运行,keras使用后端tensorflow。

问题在于:

我想使用tensorboard绘制直方图,其他训练指标图。 我按照以下程序执行此操作。

  1. 我ssh到远程GPU服务器并使用以下命令行启动了tensorboard:

    <-
  2. 此外,它还生成了以下输出

    tensorboard --port 13987 --log==/home/tharun/Desktop/logs 
    
  3. 然后我ssh到远程服务器使用以下命令行在该系统上打开firefox

    tensorboard --port 13987 --log==/home/tharun/Desktop/logs
    /home/tharun/anaconda2/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
    from ._conv import register_converters as _register_converters
    TensorBoard 0.4.0rc3 at http://sidh-pc:13987 (Press CTRL+C to quit)
    
  4. 在打开的firefox浏览器http://sidh-pc:13987中输入并打开了tensorboard页面。以下信息显示在窗口中。

    ssh -X tharun@172.26.175.67 firefox -no-remote
    
  5. 我在链接https://github.com/tensorflow/tensorboard检查了tensorboard readme.txt。然后我在终端输入以下命令并收到输出:

    No dashboards are active for the current data set.
    
    Probable causes:
    
    You haven’t written any data to your event files.
    TensorBoard can’t find your event files. 
    
    If you’re new to using TensorBoard, and want to find out how to add data and set up your event files, check out the README and perhaps the TensorBoard tutorial.
    
    If you think TensorBoard is configured properly, please see the section of the README devoted to missing data problems and consider filing an issue on GitHub.
    
    Last reload: Tue Jan 16 2018 18:17:12 GMT+0530 (IST)
    
    Log directory: =/home/tharun/Desktop/logs 
    
  6. 在检查器模式下运行tensororboard以检查事件文件的内容。

    (deep-learning) tharun@sidh-pc:~$
    find /home/tharun/Desktop/logs/ | grep tfevents
    /home/tharun/Desktop/logs/events.out.tfevents.1516101897.sidh-pc
    /home/tharun/Desktop/logs/events.out.tfevents.1516101849.sidh-pc
    

    在下一阶段,运行以下脚本(位于/ home / tharun / Desktop /)以生成更多事件文件并在tensorboard中绘制结果

    (deep-learning) tharun@sidh-pc:~$
    tensorboard --inspect --logdir /home/tharun/Desktop/logs
    /home/tharun/anaconda2/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
      from ._conv import register_converters as _register_converters
    ======================================================================
    Processing event files... (this can take a few minutes)
    ======================================================================
    
    Found event files in:
    /home/tharun/Desktop/logs
    
    These tags are in /home/tharun/Desktop/logs:
    audio -
    histograms
       dense_1/bias_0
       dense_1/bias_0_grad
       dense_1/kernel_0
       dense_1/kernel_0_grad
       dense_1_out
       dense_2/bias_0
       dense_2/bias_0_grad
       dense_2/kernel_0
       dense_2/kernel_0_grad
       dense_2_out
       dense_3/bias_0
       dense_3/bias_0_grad
       dense_3/kernel_0
       dense_3/kernel_0_grad
       dense_3_out
    images -
    scalars
       acc
       loss
       val_acc
       val_loss
    tensor -
    ======================================================================
    
    Event statistics for /home/tharun/Desktop/logs:
    audio -
    graph
       first_step           0
       last_step            0
       max_step             0
       min_step             0
       num_steps            1
       outoforder_steps     []
    histograms
       first_step           0
       last_step            149
       max_step             149
       min_step             0
       num_steps            150
       outoforder_steps     []
    images -
    scalars
       first_step           0
       last_step            149
       max_step             149
       min_step             0
       num_steps            150
       outoforder_steps     []
    sessionlog:checkpoint -
    sessionlog:start -
    sessionlog:stop -
    tensor -
    ======================================================================
    
    (deep-learning) tharun@sidh-pc:~$
    

    张量板窗口的状态没有变化。因此,我重新启动了tensorboard服务器并完成了上述类似的过程。但是firefox中的tensorboard窗口仍显示相同的状态日志:

    from keras.models import Sequential
    from keras.layers import Dense
    import numpy
    from keras.callbacks import TensorBoard
    from time import time
    # fix random seed for reproducibility
    numpy.random.seed(7)
    # load pima indians dataset
    dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
    # split into input (X) and output (Y) variables
    X = dataset[:,0:8]
    Y = dataset[:,8]
    # create model
    model = Sequential()
    model.add(Dense(12, input_dim=8, activation='relu'))
    model.add(Dense(8, activation='relu'))
    model.add(Dense(1, activation='sigmoid'))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    tensorboard =TensorBoard(log_dir='./logs', histogram_freq=1, batch_size=1, write_graph=True, write_grads=True, write_images=False, embeddings_freq=0, embeddings_layer_names=None, embeddings_metadata=None)
    
    # Fit the model
    model.fit(X, Y, epochs=150, batch_size=10, validation_split=0.2, verbose=1, callbacks=[tensorboard])
    # evaluate the model
    scores = model.evaluate(X, Y)
    print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
    

1 个答案:

答案 0 :(得分:1)

终端中的以下一行做了伎俩!!目前位于/ home / tharun / Desktop /目录

tensorboard --logdir=./
/home/tharun/anaconda2/lib/python2.7/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
TensorBoard 0.4.0rc3 at http://sidh-pc:6006 (Press CTRL+C to quit)
W0117 22:24:07.582409 Reloader plugin_event_accumulator.py:303] Found more than one graph event per run, or there was a metagraph containing a graph_def, as well as one or more graph events.  Overwriting the graph with the newest event.
W0117 22:24:42.635272 Reloader plugin_event_accumulator.py:311] Found more than one metagraph event per run. Overwriting the metagraph with the newest event.