Skip to content

Commit f26459d

Browse files
committed
Add timeline json
1 parent 5ee150c commit f26459d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

examples/keras-perf/cnn.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import tensorflow as tf
3+
from tensorflow.python.client import timeline
34
import wandb
45
from wandb.keras import WandbCallback
56

@@ -44,17 +45,27 @@
4445
model.add(tf.keras.layers.Flatten())
4546
model.add(tf.keras.layers.Dense(config.dense_layer_size, activation='relu'))
4647
model.add(tf.keras.layers.Dense(num_classes, activation='softmax'))
48+
49+
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
50+
run_metadata = tf.RunMetadata()
4751
model.compile(loss='categorical_crossentropy', optimizer='adam',
52+
options=run_options, run_metadata=run_metadata,
4853
metrics=['accuracy'])
4954
# log the number of total parameters
5055
config.total_params = model.count_params()
5156
print("Total params: ", config.total_params)
57+
5258
model.fit(X_train, y_train, validation_data=(X_test, y_test),
5359
epochs=config.epochs,
5460
callbacks=[WandbCallback(data_type="image", save_model=False),
5561
tf.keras.callbacks.TensorBoard(log_dir=wandb.run.dir)])
5662
model.save('cnn.h5')
5763

64+
# Write performance profile
65+
tl = timeline.Timeline(run_metadata.step_stats)
66+
with open('profile.json', 'w') as f:
67+
f.write(tl.generate_chrome_trace_format())
68+
5869
# Convert to TensorFlow Lite model.
5970
converter = tf.lite.TFLiteConverter.from_keras_model_file('cnn.h5')
6071
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]

examples/keras-perf/wandb/settings

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[default]
2-
entity: qualcomm
3-
project: perf-sep11
4-
base_url: https://api.wandb.ai
2+
entity = qualcomm
3+
project = perf-sep11
4+
base_url = https://api.wandb.ai
5+

0 commit comments

Comments
 (0)