Stay organized with collections
Save and categorize content based on your preferences.
Your training script must be configured to write
TensorBoard logs. For existing TensorBoard users, this requires no change to
your model training code.
To configure your training script in TensorFlow 2.x, create a
TensorBoard callback and set the log_dir variable to any location
which can connect to Google Cloud.
The TensorBoard callback is then included in the TensorFlow model.fit
callbacks list.
The TensorBoard logs are created in the specified directory and can be
uploaded to a Vertex AI TensorBoard experiment by following
the
Upload TensorBoard Logs
instructions for uploading.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Configure your training script\n\nYour training script must be configured to write\nTensorBoard logs. For existing TensorBoard users, this requires no change to\nyour model training code.\n\nTo configure your training script in TensorFlow 2.x, create a\nTensorBoard callback and set the `log_dir` variable to any location\nwhich can connect to Google Cloud.\n\nThe TensorBoard callback is then included in the TensorFlow `model.fit`\ncallbacks list. \n\n import tensorflow as tf\n\n def train_tensorflow_model_with_tensorboard(log_dir):\n (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n x_train, x_test = x_train / 255.0, x_test / 255.0\n\n def create_model():\n return tf.keras.models.Sequential(\n [\n tf.keras.layers.Flatten(input_shape=(28, 28)),\n tf.keras.layers.Dense(512, activation=\"relu\"),\n ]\n )\n\n model = create_model()\n model.compile(\n optimizer=\"adam\",\n loss=\"sparse_categorical_crossentropy\",\n metrics=[\"accuracy\"]\n )\n\n tensorboard_callback = tf.keras.callbacks.TensorBoard(\n log_dir=log_dir,\n histogram_freq=1\n )\n\n model.fit(\n x=x_train,\n y=y_train,\n epochs=5,\n validation_data=(x_test, y_test),\n callbacks=[tensorboard_callback],\n )\n\nThe TensorBoard logs are created in the specified directory and can be\nuploaded to a Vertex AI TensorBoard experiment by following\nthe\n[Upload TensorBoard Logs](/vertex-ai/docs/experiments/tensorboard-upload-existing-logs#one-time-logging)\ninstructions for uploading.\n\nFor more examples, see the [TensorBoard open source docs](https://www.tensorflow.org/tensorboard/get_started)\n\nWhat's next\n-----------\n\n- Check out automatic log streaming\n - [Train using a custom training job](/vertex-ai/docs/experiments/tensorboard-training)\n - [Train using Vertex AI Pipelines](/vertex-ai/docs/experiments/tensorboard-with-pipelines)"]]