Search code examples
pythongoogle-colaboratorywriter

How to generate a graph and visualize it from a TensorFlow code using google colab?


I'm learning TensorFlow, and now when I tried to generate graphs in google colab with the following code

import tensorflow as tf

a = tf.add(2, 2, name='add')
b = tf.multiply(a, 3, name ='mult1')
c = tf.multiply(b, a, name='mult2')

print(c.numpy())

tf.compat.v1.get_default_graph()

writer = tf.summary.create_file_writer('C:\Users\LUCINALDO\Desktop\xampp\htdocs\Deep Learning\Grafos')
a = tf.add(2, 2, name='add')
b = tf.multiply(a, 3, name ='mult1')
c = tf.multiply(b, a, name='mult2')
writer.close()

I am shown the following error message

File "<ipython-input-20-a289120d76db>", line 11
writer = tf.summary.create_file_writer('C:\Users\LUCINALDO\Desktop\xampp\htdocs\Deep Learning\Grafos')
                                      ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

How to save graph files in a computer folder(or in drive) using google colab?


Solution

  • I am able to save it as you see.

    import tensorflow as tf
    
    a = tf.add(2, 2, name='add')
    b = tf.multiply(a, 3, name ='mult1')
    c = tf.multiply(b, a, name='mult2')
    
    print(c.numpy())
    
    tf.compat.v1.get_default_graph()
    
    writer = tf.summary.create_file_writer('/test')
    a = tf.add(2, 2, name='add')
    b = tf.multiply(a, 3, name ='mult1')
    c = tf.multiply(b, a, name='mult2')
    writer.close()
    

    enter image description here