-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tensorboard Related Documentation (#187)
* Made changes related cmf init commands * Added tesorflow related document * Update mkdocs.yaml Added for testing of TensorFlow document purpose * Update document * Added image * Added image * Update tensorflow_guide.md Made chanages inside image path * kept cmf related old code inside old_archive_code directory * Removing unnecessary files * Made cmf server url as optional parameter * Made changes inside cmf client command file * Update tensorboard document * Added OSDF related parameter and Resolved Ann's Comment * Modified changes related to cmf-server page * Made changes inside README file * Made content bold * Added a disclosure widget * Updated cmf-server.md docker run commands * Updating cmf-server.md * Updating cmf-server.md * Updating ENV PATH variable as new Dockerfile guidelines * Update cmf-server.md --------- Co-authored-by: Varkha Sharma <[email protected]>
- Loading branch information
1 parent
0a66528
commit a66fd49
Showing
10 changed files
with
259 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# How to Use TensorBoard with CMF | ||
|
||
1. Copy the contents of the 'example-get-started' directory from `cmf/examples/example-get-started` into a separate directory outside cmf repository. | ||
|
||
2. Execute the following command to install the TensorFlow library in the current directory: | ||
```bash | ||
pip install tensorflow | ||
``` | ||
|
||
3. Create a new Python file (e.g., `tensorflow_log.py`) and copy the following code: | ||
|
||
``` | ||
import datetime | ||
import tensorflow as tf | ||
|
||
mnist = tf.keras.datasets.mnist | ||
(x_train, y_train),(x_test, y_test) = mnist.load_data() | ||
x_train, x_test = x_train / 255.0, x_test / 255.0 | ||
|
||
def create_model(): | ||
return tf.keras.models.Sequential([ | ||
tf.keras.layers.Flatten(input_shape=(28, 28), name='layers_flatten'), | ||
tf.keras.layers.Dense(512, activation='relu', name='layers_dense'), | ||
tf.keras.layers.Dropout(0.2, name='layers_dropout'), | ||
tf.keras.layers.Dense(10, activation='softmax', name='layers_dense_2') | ||
]) | ||
|
||
model = create_model() | ||
model.compile(optimizer='adam', | ||
loss='sparse_categorical_crossentropy', | ||
metrics=['accuracy']) | ||
|
||
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") | ||
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1) | ||
model.fit(x=x_train,y=y_train,epochs=5,validation_data=(x_test, y_test),callbacks=[tensorboard_callback]) | ||
|
||
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)) | ||
test_dataset = tf.data.Dataset.from_tensor_slices((x_test, y_test)) | ||
|
||
train_dataset = train_dataset.shuffle(60000).batch(64) | ||
test_dataset = test_dataset.batch(64) | ||
|
||
loss_object = tf.keras.losses.SparseCategoricalCrossentropy() | ||
optimizer = tf.keras.optimizers.Adam() | ||
|
||
# Define our metrics | ||
train_loss = tf.keras.metrics.Mean('train_loss', dtype=tf.float32) | ||
train_accuracy = tf.keras.metrics.SparseCategoricalAccuracy('train_accuracy') | ||
test_loss = tf.keras.metrics.Mean('test_loss', dtype=tf.float32) | ||
test_accuracy = tf.keras.metrics.SparseCategoricalAccuracy('test_accuracy') | ||
|
||
def train_step(model, optimizer, x_train, y_train): | ||
with tf.GradientTape() as tape: | ||
predictions = model(x_train, training=True) | ||
loss = loss_object(y_train, predictions) | ||
grads = tape.gradient(loss, model.trainable_variables) | ||
optimizer.apply_gradients(zip(grads, model.trainable_variables)) | ||
train_loss(loss) | ||
train_accuracy(y_train, predictions) | ||
|
||
def test_step(model, x_test, y_test): | ||
predictions = model(x_test) | ||
loss = loss_object(y_test, predictions) | ||
test_loss(loss) | ||
test_accuracy(y_test, predictions) | ||
|
||
current_time = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") | ||
train_log_dir = 'logs/gradient_tape/' + current_time + '/train' | ||
test_log_dir = 'logs/gradient_tape/' + current_time + '/test' | ||
train_summary_writer = tf.summary.create_file_writer(train_log_dir) | ||
test_summary_writer = tf.summary.create_file_writer(test_log_dir) | ||
|
||
model = create_model() # reset our model | ||
EPOCHS = 5 | ||
for epoch in range(EPOCHS): | ||
for (x_train, y_train) in train_dataset: | ||
train_step(model, optimizer, x_train, y_train) | ||
with train_summary_writer.as_default(): | ||
tf.summary.scalar('loss', train_loss.result(), step=epoch) | ||
tf.summary.scalar('accuracy', train_accuracy.result(), step=epoch) | ||
|
||
for (x_test, y_test) in test_dataset: | ||
test_step(model, x_test, y_test) | ||
with test_summary_writer.as_default(): | ||
tf.summary.scalar('loss', test_loss.result(), step=epoch) | ||
tf.summary.scalar('accuracy', test_accuracy.result(), step=epoch) | ||
template = 'Epoch {}, Loss: {}, Accuracy: {}, Test Loss: {}, Test Accuracy: {}' | ||
print (template.format(epoch+1, | ||
train_loss.result(), | ||
train_accuracy.result()*100, | ||
test_loss.result(), | ||
test_accuracy.result()*100)) | ||
|
||
``` | ||
For more detailed information, check out the [TensorBoard documentation](https://www.tensorflow.org/tensorboard/get_started). | ||
5. Execute the TensorFlow log script using the following command: | ||
```bash | ||
python3 tensorflow_log.py | ||
``` | ||
6. The above script will automatically create a `logs` directory inside your current directory. | ||
7. Start the CMF server and configure the [CMF client](step-by-step.md). | ||
8. Use the following command to run the test script, which will generate the MLMD file: | ||
```bash | ||
sh test_script.sh | ||
``` | ||
9. Use the following command to push the generated MLMD and TensorFlow log files to the CMF server: | ||
```bash | ||
cmf metadata push -p 'pipeline-name' -t 'tensorboard-log-file-name' | ||
``` | ||
10. Go to the CMF server and navigate to the TensorBoard tab. You will see an interface similar to the following image. | ||
![image](../assets/Tensorboard.png) | ||
--- |
Oops, something went wrong.