首页 > 解决方案 > 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?

标签: pythongoogle-colaboratorywriter

解决方案


如您所见,我可以保存它。

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()

在此处输入图像描述


推荐阅读