Configure your training script Stay organized with collections Save and categorize content based on your preferences.
Your training script must be configured to writeTensorBoard logs. For existing TensorBoard users, this requires no change toyour model training code.
To configure your training script in TensorFlow 2.x, create aTensorBoard callback and set thelog_dir variable to any locationwhich can connect to Google Cloud.
The TensorBoard callback is then included in the TensorFlowmodel.fitcallbacks list.
importtensorflowastfdeftrain_tensorflow_model_with_tensorboard(log_dir):(x_train,y_train),(x_test,y_test)=tf.keras.datasets.mnist.load_data()x_train,x_test=x_train/255.0,x_test/255.0defcreate_model():returntf.keras.models.Sequential([tf.keras.layers.Flatten(input_shape=(28,28)),tf.keras.layers.Dense(512,activation="relu"),])model=create_model()model.compile(optimizer="adam",loss="sparse_categorical_crossentropy",metrics=["accuracy"])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],)The TensorBoard logs are created in the specified directory and can beuploaded to a Vertex AI TensorBoard experiment by followingtheUpload TensorBoard Logsinstructions for uploading.
For more examples, see theTensorBoard open source docs
What's next
- Check out automatic log streaming
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.