{ "cells": [ { "cell_type": "code", "execution_count": null, "source": [ "# Reference: https://github.com/tensorflow/docs/blob/master/site/en/guide/migrate/tensorboard.ipynb\n", "import tensorflow as tf\n", "import tempfile\n", "import numpy as np\n", "import datetime" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "mnist = tf.keras.datasets.mnist # The MNIST dataset.\n", "\n", "(x_train, y_train),(x_test, y_test) = mnist.load_data()\n", "x_train, x_test = x_train / 255.0, x_test / 255.0" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": null, "source": [ "def create_model():\n", " return tf.keras.models.Sequential([\n", " tf.keras.layers.Flatten(input_shape=(28, 28)),\n", " tf.keras.layers.Dense(512, activation='relu'),\n", " tf.keras.layers.Dropout(0.2),\n", " tf.keras.layers.Dense(10, activation='softmax')\n", " ])\n", "\n", "model = create_model()\n", "model.compile(optimizer='adam',\n", " loss='sparse_categorical_crossentropy',\n", " metrics=['accuracy'],\n", " steps_per_execution=10)\n", "\n", "log_dir = 'tflogs'\n", "tensorboard_callback = tf.keras.callbacks.TensorBoard(\n", " log_dir=log_dir,\n", " histogram_freq=1) # Enable histogram computation with each epoch.\n", "\n", "model.fit(x=x_train,\n", " y=y_train,\n", " epochs=10,\n", " validation_data=(x_test, y_test),\n", " callbacks=[tensorboard_callback])" ], "outputs": [], "metadata": {} } ], "metadata": { "orig_nbformat": 4, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }