Demonstrate basic graph writing.
()
| 46 | |
| 47 | |
| 48 | def write_graph(): |
| 49 | """Demonstrate basic graph writing.""" |
| 50 | logdir = os.path.join(LOGDIR, "write_graph") |
| 51 | |
| 52 | @tf.function |
| 53 | def f(): |
| 54 | x = tf.constant(2) |
| 55 | y = tf.constant(3) |
| 56 | return x**y |
| 57 | |
| 58 | with tf.summary.create_file_writer(logdir).as_default(): |
| 59 | if hasattr(tf.summary, "graph"): |
| 60 | # Emit a simple graph. |
| 61 | tf.summary.graph(f.get_concrete_function().graph) |
| 62 | else: |
| 63 | print( |
| 64 | "Could not find tf.summary.graph(); use TF 2.5.0+ to run full demo" |
| 65 | ) |
| 66 | |
| 67 | |
| 68 | def keras(): |