MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / keras

Function keras

tensorboard/plugins/graph/graphs_demo.py:68–103  ·  view source on GitHub ↗

Create a Keras conceptual graph and op graphs. The `keras/train` run has a run-level graph, a `batch_2` tag with op graph only (`graph_run_metadata_graph` plugin), and a `keras` tag with a Keras conceptual graph only (`graph_keras_model` plugin).

()

Source from the content-addressed store, hash-verified

66
67
68def keras():
69 """Create a Keras conceptual graph and op graphs.
70
71 The `keras/train` run has a run-level graph, a `batch_2` tag with op
72 graph only (`graph_run_metadata_graph` plugin), and a `keras` tag
73 with a Keras conceptual graph only (`graph_keras_model` plugin).
74 """
75 logdir = os.path.join(LOGDIR, "keras")
76
77 data_size = 1000
78 train_fac = 0.8
79 train_size = int(data_size * train_fac)
80 x = np.linspace(-1, 1, data_size)
81 np.random.shuffle(x)
82 y = 0.5 * x + 2 + np.random.normal(0, 0.05, (data_size,))
83 (x_train, y_train) = x[:train_size], y[:train_size]
84 (x_test, y_test) = x[train_size:], y[train_size:]
85
86 layers = [
87 tf.keras.layers.Dense(16, input_dim=1),
88 tf.keras.layers.Dense(1),
89 ]
90 model = tf.keras.models.Sequential(layers)
91 model.compile(
92 loss=tf.keras.losses.mean_squared_error,
93 optimizer=tf.keras.optimizers.SGD(learning_rate=0.2),
94 )
95 model.fit(
96 x_train,
97 y_train,
98 batch_size=train_size,
99 verbose=0,
100 epochs=100,
101 validation_data=(x_test, y_test),
102 callbacks=[tf.keras.callbacks.TensorBoard(logdir)],
103 )
104
105
106def profile():

Callers 1

mainFunction · 0.85

Calls 2

joinMethod · 0.45
fitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…