geek
geek

Reputation: 65

Getting tensorboard to work with keras

I have an issue that seems to have no straight forward solution in Keras. My server runs on ubuntu 14.04, keras with backend tensorflow.

Here's the issue:

I wanted to use tensorboard to plot the histograms, other training metrics graphs. I followed the following procedure to do so.

  1. I ssh'd to the remote GPU server and started tensorboard with the following command line:

    tensorboard --port 13987 --log==/home/tharun/Desktop/logs 
    
  2. Further it generated the following output

    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)
    
  3. Then I ssh'd to the remote server to open firefox on that system with the following command line

    ssh -X [email protected] firefox -no-remote
    
  4. In the opened firefox browser http://sidh-pc:13987 was typed in and it opened the tensorboard page. Following information is shown in the window.

    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 
    
  5. Being confused I checked tensorboard readme.txt at the link https://github.com/tensorflow/tensorboard . Then I typed in the following command in terminal and received the output:

    (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
    
  6. Ran tensorboard in inspector mode to inspect the contents of the event files.

    (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:~$
    

    In the next stage, following script (located at /home/tharun/Desktop/) is run to produce more event files and plot the results in 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))
    

    There was no change in the status of tensorboard window. Hence I have restarted the tensorboard server and went through the similar procedure outlined above. But still the tensorboard window in firefox shows the same status log:

    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:46:45 GMT+0530 (IST)
    
    Log directory: =/home/tharun/Desktop/logs  
    

Upvotes: 1

Views: 1963

Answers (1)

geek
geek

Reputation: 65

The following line in terminal did the trick!! Currently situated in /home/tharun/Desktop/ directory

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.

Upvotes: 1

Related Questions