TensorFlow

Save and load TensorFlow model

Original page https://www.tensorflow.org/tutorials/keras/save_and_load Show model details import tensorflow as tf def create_model(): model = tf.keras.models.Sequential([ tf.keras.layers.Dense(512, activation='relu', input_shape=(784,)), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10) ]) model.compile(optimizer='adam', loss=tf.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) return model # Create a basic model instance model = create_model() # Display the model's architecture model.summary() Load MNIST data # MNIST (train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data() train_labels = train_labels[:1000] test_labels = test_labels[:1000] train_images = train_images[:1000].reshape(-1, 28 * 28) / 255.0 test_images = test_images[:1000].reshape(-1, 28 * 28) / 255.

Enabling TensorFlow using GPU

We can install TensorFlow via pip easily, but we should care a little bit more if you want to enable GPU. Requirements https://www.tensorflow.org/install/gpu#software_requirements #Here is how I installed my NVIDIA GPU environment. Install Pre requirements sudo apt-get install libcupti-dev #already installed in my case echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc Install cuDNN Download a compatible version from https://developer.nvidia.com/rdp/cudnn-download. tar -xzvf cudnn-10.2-linux-x64-v8.0.1.13.tgz sudo cp cuda/include/cudnn*.h /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn*.

TensorBoard

TensorBoard We can easily visualize our neural networks written by TensorFlow in a graph format with TensorBoard (it can more actually). https://www.tensorflow.org/tensorboard/get_started Install As of 2020/07/09, TensorBoard is installed when you install TensorFlow with pip. pip install -U tensorboard <- it already installed when you install tensorflow with pip. it coflict and cause problem Simple sampl code First, create a smiple model. mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.

Tensorflow architecture

Official https://github.com/tensorflow/docs/blob/master/site/en/r1/guide/extend/architecture.md TensorFlow has master, client, worker components. You can imagine a distributed system, and it is correct. TensorFlow is designed to make a cluster. Distributed TensorFlow And here is the official document about distributed TensorFlow with sample codes. https://github.com/tensorflow/examples/blob/master/community/en/docs/deploy/distributed.md Another Sample Here is sample cluster code by IONOS (one of the biggest German ISP.) https://www.ionos.de/community/server-cloud-infrastructure/tensorflow/einrichten-eines-verteilten-tensorflow-clusters-auf-cloud-servern/ You can see there is parameter servers and worker servers.

Tensorflow - step by step

Intro - Official quickstart for beginners https://www.tensorflow.org/tutorials/quickstart/beginner Import TensorFlow library and load official MNIST dataset. import tensorflow as tf mnist = tf.keras.datasets.mnist Split MNIST dataset into training and dataset. and regularize (from 0 to 1). (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 The meaning of values is quoted below. https://conx.readthedocs.io/en/latest/MNIST.html The MNIST digits are grayscale images, with each pixel represented as a single intensity value in the range 0 (black) to 1 (white).