{
  "source_file": "0930",
  "source_platform": "Hashnode",
  "author": "Wesley Kambale",
  "title_listed": "Setting Up a TensorBoard in Google Colab",
  "keywords": "",
  "domain": "机器学习",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://kambale.dev/setting-up-a-tensorboard",
  "publish_date": "2023-09-03",
  "corpus_stage": "",
  "notes": "",
  "id": "097131a1461d",
  "collected_at": "2026-10-02T14:11:29",
  "title": "Setting Up a TensorBoard in Google Colab",
  "body_markdown": "Setting Up a TensorBoard in Google Colab\nA Guide to Setting Up a TensorBoard in Google Colab\nPublished\nSeptember 3, 2023\n•\n2\nmin read\n•\nView as Markdown\nW\nWesley Kambale\nI'm a Machine Learning Engineer passionate about building production-ready ML systems for the African market.\nWith experience in TensorFlow, Keras, and Python-based workflows, I help teams bridge the gap between machine learning research and real-world deployment—especially on resource-constrained devices.\nI'm also a Google Developer Expert in AI. I regularly speak at tech conferences including PyCon Africa, DevFest Kampala, DevFest Nairobi and more and also write technical articles on AI/ML here.\nIntroduction\nSetting up TensorBoard in Google Colab can be incredibly useful for visualizing your machine learning model's training progress and performance. TensorBoard is a powerful tool that helps you monitor various metrics, visualize model architectures, and gain insights into your model's behavior. Here's a step-by-step tutorial with examples and code snippets to guide you through the process.\nImport Necessary Libraries\nFirst, you need to import the required libraries. Make sure you have TensorFlow installed in your Colab environment.\nimport\ntensorflow\nas\ntf\nfrom\ntensorboard\nimport\nnotebook\nLoad and Prepare Your Data\nFor demonstration purposes, let's use a simple dataset. Replace this with your actual dataset and preprocessing steps.\n# Load and preprocess your data\n(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\nx_train, x_test = x_train /\n255.0\n, x_test /\n255.0\n# Normalize pixel values\nBuild and Compile Your Model\nAgain, this is just a simple example. Replace it with your actual model architecture and configuration.\nmodel = tf.keras.Sequential([\n    tf.keras.layers.Flatten(input_shape=(\n28\n,\n28\n)),\n    tf.keras.layers.Dense(\n128\n, activation=\n'relu'\n),\n    tf.keras.layers.Dropout(\n0.2\n),\n    tf.keras.layers.Dense(\n10\n)\n])\n# Compile the model\nloss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=\nTrue\n)\nmodel.compile(optimizer=\n'adam'\n, loss=loss_fn, metrics=[\n'accuracy'\n])\nSet Up TensorBoard Callback\nNow, you'll create a TensorBoard callback that will save logs for visualization.\n# Define the log directory\nlog_dir =\n\"/content/logs\"\n# You can modify this path\n# Create a TensorBoard callback\ntensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=\n1\n)\nTrain Your Model\nTrain your model using the\nfit\nfunction and include the TensorBoard callback.\n# Train the model\nmodel.fit(x_train, y_train, epochs=\n5\n, callbacks=[tensorboard_callback])\nStart TensorBoard in Colab\nTensorBoard can be started directly within a Colab notebook using the\nnotebook\nmodule.\n# Load TensorBoard in Colab\nnotebook.start(\n'--logdir '\n+ log_dir)\nAccess and Visualize TensorBoard\nAfter running the previous cell, you'll see a link to access TensorBoard. Click on that link to open TensorBoard within your Colab environment. You can navigate through various tabs to visualize different aspects of your training process.\nStop TensorBoard\nOnce you're done with TensorBoard, you can stop it using the \"Stop\" button in the TensorBoard UI, or you can run the following code to stop the TensorBoard instance:\nnotebook.stop()\nConclusion\nThat's it! You've successfully set up TensorBoard in Google Colab to monitor and visualize your model's training progress.\nRemember that this tutorial provided a basic example. Depending on your use case, you might need to adjust the code to suit your specific model architecture, dataset, and training configuration.\n#\ntensorboard\n#\ntensorflow\n#\ngoogle-colab",
  "metadata": {
    "title": "Setting Up a TensorBoard in Google Colab",
    "description": "A Guide to Setting Up a TensorBoard in Google Colab",
    "keywords": null,
    "author": null,
    "og:title": "Setting Up a TensorBoard in Google Colab",
    "og:description": "A Guide to Setting Up a TensorBoard in Google Colab",
    "og:url": "https://kambale.dev/setting-up-a-tensorboard",
    "og:site_name": "Wesley Kambale",
    "og:image": "https://cdn.hashnode.com/res/hashnode/image/upload/v1692189864692/167bdf89-45a4-40d6-82de-be582c2b72c7.png",
    "og:image:width": "1200",
    "og:image:height": "630",
    "og:type": "article",
    "twitter:card": "summary_large_image",
    "twitter:creator": "https://twitter.com/WesKambale",
    "twitter:title": "Setting Up a TensorBoard in Google Colab",
    "twitter:description": "A Guide to Setting Up a TensorBoard in Google Colab",
    "twitter:image": "https://cdn.hashnode.com/res/hashnode/image/upload/v1692189864692/167bdf89-45a4-40d6-82de-be582c2b72c7.png",
    "article:published_time": "2023-09-03T21:00:00.000Z",
    "article:author": "https://kambale.dev/@kambale"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/097131a1461d/code/body-000.txt",
      "chars": 57,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-001.txt",
      "chars": 183,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-002.txt",
      "chars": 362,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-003.txt",
      "chars": 203,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-004.txt",
      "chars": 90,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-005.txt",
      "chars": 66,
      "language": "text"
    },
    {
      "file": "attachments/097131a1461d/code/body-006.txt",
      "chars": 16,
      "language": "text"
    }
  ],
  "images": [
    {
      "status": "ok",
      "url": "https://cdn.hashnode.com/res/hashnode/image/upload/v1692189864692/167bdf89-45a4-40d6-82de-be582c2b72c7.png",
      "bytes": 148205,
      "reused": true,
      "local_path": "attachments/097131a1461d/images/000.png",
      "src": "https://cdn.hashnode.com/res/hashnode/image/upload/v1692189864692/167bdf89-45a4-40d6-82de-be582c2b72c7.png",
      "alt": "Setting Up a TensorBoard in Google Colab",
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://kambale.dev/setting-up-a-tensorboard.md",
      "label": "View as Markdown",
      "type": "a"
    },
    {
      "href": "https://hashnode.com/@kambale",
      "label": "W",
      "type": "a"
    },
    {
      "href": "https://twitter.com/WesKambale",
      "label": "",
      "type": "a"
    },
    {
      "href": "https://linkedin.com/in/WesKambale",
      "label": "",
      "type": "a"
    },
    {
      "href": "https://kambale.dev/tag/tensorboard",
      "label": "# tensorboard",
      "type": "a"
    },
    {
      "href": "https://kambale.dev/tag/tensorflow",
      "label": "# tensorflow",
      "type": "a"
    },
    {
      "href": "https://kambale.dev/tag/google-colab",
      "label": "# google-colab",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:50:50Z",
  "source_url": "https://kambale.dev/setting-up-a-tensorboard",
  "papers": [],
  "actual_video_files": [],
  "body_chars": 3638,
  "expected_body_images": 1,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/097131a1461d/pages/source.html",
  "local_html": "attachments/097131a1461d/pages/article.html",
  "body_base_path": "attachments/097131a1461d/pages/",
  "body_markdown_path": "attachments/097131a1461d/pages/article.md"
}