0

I am new to tensorflow and I am learning it using a book called Deep Learning with Applications Using Python Chatbots and Face, Object,and Speech Recognition With TensorFlow and Keras.

On Chapter 1 page 6, there are lines of code:

enter image description here

And I typed the codes showed in the book exactly,

# Tensorboard can be used. It is optionalmy_
# Output graph can be seen on tensorboard
import os
merged = tf.summary.merge_all(key='summaries')
if not os.path.exists('tensorboard_logs/'):
    os.makedirs('tenosrboard_logs/')

my_writer = tf.summary.FileWriter('/home/manaswi/tenosrboard_logs/', sess.graph)

def TB(cleanup=False):
    import webbrowser
    webbrowser.open('http://127.0.1.1:6006')
    !tensorboard --logdir='/home/manaswi/tenosrboard_logs'

    if cleanup:
        !rm -R tensorboard_logs/


TB(1)   # Launch graph on tensorboard on your browser

But I get a syntax error when I run this code.

  File "c1_demo.py", line 26
    !tensorboard --logdir='/home/manaswi/tenosrboard_logs'
    ^
SyntaxError: invalid syntax

Am I doing something wrong or is the code problem.

1 Answer 1

2

The code of your book is written in a jupyter notebook and a special function of the jupyter notebook (jupyter magiv) is that the ! command executes a command in the console.

If you use another IDE use this function instead:

def TB(cleanup=False):
    import webbrowser
    os.system(tensorboard --logdir='/home/manaswi/tenosrboard_logs')
    webbrowser.open('http://127.0.1.1:6006')

And two additional things:

  1. It is better to make your imports at the beginning of the code in case something went wrong
  2. Tensorobard need a little bit time to start, so it is better to first create the the tensorboard and then open it
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.