diff --git a/examples/vision/forwardforward.py b/examples/vision/forwardforward.py index 6032eeeb41..ee0d8573c3 100644 --- a/examples/vision/forwardforward.py +++ b/examples/vision/forwardforward.py @@ -2,7 +2,7 @@ Title: Using the Forward-Forward Algorithm for Image Classification Author: [Suvaditya Mukherjee](https://twitter.com/halcyonrayes) Date created: 2023/01/08 -Last modified: 2023/01/08 +Last modified: 2024/09/17 Description: Training a Dense-layer model using the Forward-Forward algorithm. Accelerator: GPU """ @@ -59,9 +59,13 @@ """ ## Setup imports """ +import os + +os.environ["KERAS_BACKEND"] = "tensorflow" import tensorflow as tf -from tensorflow import keras +import keras +from keras import ops import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import accuracy_score @@ -143,7 +147,7 @@ class FFDense(keras.layers.Layer): def __init__( self, units, - optimizer, + init_optimizer, loss_metric, num_epochs=50, use_bias=True, @@ -163,7 +167,7 @@ def __init__( bias_regularizer=bias_regularizer, ) self.relu = keras.layers.ReLU() - self.optimizer = optimizer + self.optimizer = init_optimizer() self.loss_metric = loss_metric self.threshold = 1.5 self.num_epochs = num_epochs @@ -172,7 +176,7 @@ def __init__( # layer. def call(self, x): - x_norm = tf.norm(x, ord=2, axis=1, keepdims=True) + x_norm = ops.norm(x, ord=2, axis=1, keepdims=True) x_norm = x_norm + 1e-4 x_dir = x / x_norm res = self.dense(x_dir) @@ -192,22 +196,24 @@ def call(self, x): def forward_forward(self, x_pos, x_neg): for i in range(self.num_epochs): with tf.GradientTape() as tape: - g_pos = tf.math.reduce_mean(tf.math.pow(self.call(x_pos), 2), 1) - g_neg = tf.math.reduce_mean(tf.math.pow(self.call(x_neg), 2), 1) + g_pos = ops.mean(ops.power(self.call(x_pos), 2), 1) + g_neg = ops.mean(ops.power(self.call(x_neg), 2), 1) - loss = tf.math.log( + loss = ops.log( 1 - + tf.math.exp( - tf.concat([-g_pos + self.threshold, g_neg - self.threshold], 0) + + ops.exp( + ops.concatenate( + [-g_pos + self.threshold, g_neg - self.threshold], 0 + ) ) ) - mean_loss = tf.cast(tf.math.reduce_mean(loss), tf.float32) + mean_loss = ops.cast(ops.mean(loss), dtype="float32") self.loss_metric.update_state([mean_loss]) gradients = tape.gradient(mean_loss, self.dense.trainable_weights) self.optimizer.apply_gradients(zip(gradients, self.dense.trainable_weights)) return ( - tf.stop_gradient(self.call(x_pos)), - tf.stop_gradient(self.call(x_neg)), + ops.stop_gradient(self.call(x_pos)), + ops.stop_gradient(self.call(x_neg)), self.loss_metric.result(), ) @@ -248,25 +254,24 @@ class FFNetwork(keras.Model): # the `Adam` optimizer with a default learning rate of 0.03 as that was # found to be the best rate after experimentation. # Loss is tracked using `loss_var` and `loss_count` variables. - # Use legacy optimizer for Layer Optimizer to fix issue - # https://github.com/keras-team/keras-io/issues/1241 def __init__( self, dims, - layer_optimizer=keras.optimizers.legacy.Adam(learning_rate=0.03), + init_layer_optimizer=lambda: keras.optimizers.Adam(learning_rate=0.03), **kwargs, ): super().__init__(**kwargs) - self.layer_optimizer = layer_optimizer - self.loss_var = tf.Variable(0.0, trainable=False, dtype=tf.float32) - self.loss_count = tf.Variable(0.0, trainable=False, dtype=tf.float32) + self.init_layer_optimizer = init_layer_optimizer + self.loss_var = keras.Variable(0.0, trainable=False, dtype="float32") + self.loss_count = keras.Variable(0.0, trainable=False, dtype="float32") self.layer_list = [keras.Input(shape=(dims[0],))] + self.metrics_built = False for d in range(len(dims) - 1): self.layer_list += [ FFDense( dims[d + 1], - optimizer=self.layer_optimizer, + init_optimizer=self.init_layer_optimizer, loss_metric=keras.metrics.Mean(), ) ] @@ -280,9 +285,9 @@ def __init__( @tf.function(reduce_retracing=True) def overlay_y_on_x(self, data): X_sample, y_sample = data - max_sample = tf.reduce_max(X_sample, axis=0, keepdims=True) - max_sample = tf.cast(max_sample, dtype=tf.float64) - X_zeros = tf.zeros([10], dtype=tf.float64) + max_sample = ops.amax(X_sample, axis=0, keepdims=True) + max_sample = ops.cast(max_sample, dtype="float64") + X_zeros = ops.zeros([10], dtype="float64") X_update = xla.dynamic_update_slice(X_zeros, max_sample, [y_sample]) X_sample = xla.dynamic_update_slice(X_sample, X_update, [0]) return X_sample, y_sample @@ -297,25 +302,23 @@ def overlay_y_on_x(self, data): @tf.function(reduce_retracing=True) def predict_one_sample(self, x): goodness_per_label = [] - x = tf.reshape(x, [tf.shape(x)[0] * tf.shape(x)[1]]) + x = ops.reshape(x, [ops.shape(x)[0] * ops.shape(x)[1]]) for label in range(10): h, label = self.overlay_y_on_x(data=(x, label)) - h = tf.reshape(h, [-1, tf.shape(h)[0]]) + h = ops.reshape(h, [-1, ops.shape(h)[0]]) goodness = [] for layer_idx in range(1, len(self.layer_list)): layer = self.layer_list[layer_idx] h = layer(h) - goodness += [tf.math.reduce_mean(tf.math.pow(h, 2), 1)] - goodness_per_label += [ - tf.expand_dims(tf.reduce_sum(goodness, keepdims=True), 1) - ] + goodness += [ops.mean(ops.power(h, 2), 1)] + goodness_per_label += [ops.expand_dims(ops.sum(goodness, keepdims=True), 1)] goodness_per_label = tf.concat(goodness_per_label, 1) - return tf.cast(tf.argmax(goodness_per_label, 1), tf.float64) + return ops.cast(ops.argmax(goodness_per_label, 1), dtype="float64") def predict(self, data): x = data preds = list() - preds = tf.map_fn(fn=self.predict_one_sample, elems=x) + preds = ops.vectorized_map(self.predict_one_sample, x) return np.asarray(preds, dtype=int) # This custom `train_step` function overrides the internal `train_step` @@ -328,17 +331,26 @@ def predict(self, data): # the Forward-Forward computation on it. The returned loss is the final # loss value over all the layers. - @tf.function(jit_compile=True) + @tf.function(jit_compile=False) def train_step(self, data): x, y = data + if not self.metrics_built: + # build metrics to ensure they can be queried without erroring out. + # We can't update the metrics' state, as we would usually do, since + # we do not perform predictions within the train step + for metric in self.metrics: + if hasattr(metric, "build"): + metric.build(y, y) + self.metrics_built = True + # Flatten op - x = tf.reshape(x, [-1, tf.shape(x)[1] * tf.shape(x)[2]]) + x = ops.reshape(x, [-1, ops.shape(x)[1] * ops.shape(x)[2]]) - x_pos, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, y)) + x_pos, y = ops.vectorized_map(self.overlay_y_on_x, (x, y)) random_y = tf.random.shuffle(y) - x_neg, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, random_y)) + x_neg, y = tf.map_fn(self.overlay_y_on_x, (x, random_y)) h_pos, h_neg = x_pos, x_neg @@ -351,7 +363,7 @@ def train_step(self, data): else: print(f"Passing layer {idx+1} now : ") x = layer(x) - mean_res = tf.math.divide(self.loss_var, self.loss_count) + mean_res = ops.divide(self.loss_var, self.loss_count) return {"FinalLoss": mean_res} @@ -386,8 +398,8 @@ def train_step(self, data): model.compile( optimizer=keras.optimizers.Adam(learning_rate=0.03), loss="mse", - jit_compile=True, - metrics=[keras.metrics.Mean()], + jit_compile=False, + metrics=[], ) epochs = 250 @@ -400,7 +412,7 @@ def train_step(self, data): test set. We calculate the Accuracy Score to understand the results closely. """ -preds = model.predict(tf.convert_to_tensor(x_test)) +preds = model.predict(ops.convert_to_tensor(x_test)) preds = preds.reshape((preds.shape[0], preds.shape[1])) diff --git a/examples/vision/img/forwardforward/forwardforward_15_1.png b/examples/vision/img/forwardforward/forwardforward_15_1.png index 0e95f8e1b8..7d29e9a8a2 100644 Binary files a/examples/vision/img/forwardforward/forwardforward_15_1.png and b/examples/vision/img/forwardforward/forwardforward_15_1.png differ diff --git a/examples/vision/img/forwardforward/forwardforward_5_1.png b/examples/vision/img/forwardforward/forwardforward_5_1.png index 8d7b00b6c0..6b63c595ea 100644 Binary files a/examples/vision/img/forwardforward/forwardforward_5_1.png and b/examples/vision/img/forwardforward/forwardforward_5_1.png differ diff --git a/examples/vision/ipynb/forwardforward.ipynb b/examples/vision/ipynb/forwardforward.ipynb index 372e92a965..d0837d39b8 100644 --- a/examples/vision/ipynb/forwardforward.ipynb +++ b/examples/vision/ipynb/forwardforward.ipynb @@ -1,7 +1,6 @@ { "cells": [ { - "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text" @@ -11,7 +10,7 @@ "\n", "**Author:** [Suvaditya Mukherjee](https://twitter.com/halcyonrayes)
\n", "**Date created:** 2023/01/08
\n", - "**Last modified:** 2023/01/08
\n", + "**Last modified:** 2024/09/17
\n", "**Description:** Training a Dense-layer model using the Forward-Forward algorithm." ] }, @@ -80,14 +79,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, "outputs": [], "source": [ + "import os\n", + "\n", + "os.environ[\"KERAS_BACKEND\"] = \"tensorflow\"\n", + "\n", "import tensorflow as tf\n", - "from tensorflow import keras\n", + "import keras\n", + "from keras import ops\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from sklearn.metrics import accuracy_score\n", @@ -113,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, @@ -180,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, @@ -197,7 +201,7 @@ " def __init__(\n", " self,\n", " units,\n", - " optimizer,\n", + " init_optimizer,\n", " loss_metric,\n", " num_epochs=50,\n", " use_bias=True,\n", @@ -217,7 +221,7 @@ " bias_regularizer=bias_regularizer,\n", " )\n", " self.relu = keras.layers.ReLU()\n", - " self.optimizer = optimizer\n", + " self.optimizer = init_optimizer()\n", " self.loss_metric = loss_metric\n", " self.threshold = 1.5\n", " self.num_epochs = num_epochs\n", @@ -226,7 +230,7 @@ " # layer.\n", "\n", " def call(self, x):\n", - " x_norm = tf.norm(x, ord=2, axis=1, keepdims=True)\n", + " x_norm = ops.norm(x, ord=2, axis=1, keepdims=True)\n", " x_norm = x_norm + 1e-4\n", " x_dir = x / x_norm\n", " res = self.dense(x_dir)\n", @@ -246,24 +250,27 @@ " def forward_forward(self, x_pos, x_neg):\n", " for i in range(self.num_epochs):\n", " with tf.GradientTape() as tape:\n", - " g_pos = tf.math.reduce_mean(tf.math.pow(self.call(x_pos), 2), 1)\n", - " g_neg = tf.math.reduce_mean(tf.math.pow(self.call(x_neg), 2), 1)\n", + " g_pos = ops.mean(ops.power(self.call(x_pos), 2), 1)\n", + " g_neg = ops.mean(ops.power(self.call(x_neg), 2), 1)\n", "\n", - " loss = tf.math.log(\n", + " loss = ops.log(\n", " 1\n", - " + tf.math.exp(\n", - " tf.concat([-g_pos + self.threshold, g_neg - self.threshold], 0)\n", + " + ops.exp(\n", + " ops.concatenate(\n", + " [-g_pos + self.threshold, g_neg - self.threshold], 0\n", + " )\n", " )\n", " )\n", - " mean_loss = tf.cast(tf.math.reduce_mean(loss), tf.float32)\n", + " mean_loss = ops.cast(ops.mean(loss), dtype=\"float32\")\n", " self.loss_metric.update_state([mean_loss])\n", " gradients = tape.gradient(mean_loss, self.dense.trainable_weights)\n", " self.optimizer.apply_gradients(zip(gradients, self.dense.trainable_weights))\n", " return (\n", - " tf.stop_gradient(self.call(x_pos)),\n", - " tf.stop_gradient(self.call(x_neg)),\n", + " ops.stop_gradient(self.call(x_pos)),\n", + " ops.stop_gradient(self.call(x_neg)),\n", " self.loss_metric.result(),\n", - " )\n" + " )\n", + "" ] }, { @@ -295,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, @@ -315,25 +322,24 @@ " # the `Adam` optimizer with a default learning rate of 0.03 as that was\n", " # found to be the best rate after experimentation.\n", " # Loss is tracked using `loss_var` and `loss_count` variables.\n", - " # Use legacy optimizer for Layer Optimizer to fix issue\n", - " # https://github.com/keras-team/keras-io/issues/1241\n", "\n", " def __init__(\n", " self,\n", " dims,\n", - " layer_optimizer=keras.optimizers.legacy.Adam(learning_rate=0.03),\n", + " init_layer_optimizer=lambda: keras.optimizers.Adam(learning_rate=0.03),\n", " **kwargs,\n", " ):\n", " super().__init__(**kwargs)\n", - " self.layer_optimizer = layer_optimizer\n", - " self.loss_var = tf.Variable(0.0, trainable=False, dtype=tf.float32)\n", - " self.loss_count = tf.Variable(0.0, trainable=False, dtype=tf.float32)\n", + " self.init_layer_optimizer = init_layer_optimizer\n", + " self.loss_var = keras.Variable(0.0, trainable=False, dtype=\"float32\")\n", + " self.loss_count = keras.Variable(0.0, trainable=False, dtype=\"float32\")\n", " self.layer_list = [keras.Input(shape=(dims[0],))]\n", + " self.metrics_built = False\n", " for d in range(len(dims) - 1):\n", " self.layer_list += [\n", " FFDense(\n", " dims[d + 1],\n", - " optimizer=self.layer_optimizer,\n", + " init_optimizer=self.init_layer_optimizer,\n", " loss_metric=keras.metrics.Mean(),\n", " )\n", " ]\n", @@ -347,9 +353,9 @@ " @tf.function(reduce_retracing=True)\n", " def overlay_y_on_x(self, data):\n", " X_sample, y_sample = data\n", - " max_sample = tf.reduce_max(X_sample, axis=0, keepdims=True)\n", - " max_sample = tf.cast(max_sample, dtype=tf.float64)\n", - " X_zeros = tf.zeros([10], dtype=tf.float64)\n", + " max_sample = ops.amax(X_sample, axis=0, keepdims=True)\n", + " max_sample = ops.cast(max_sample, dtype=\"float64\")\n", + " X_zeros = ops.zeros([10], dtype=\"float64\")\n", " X_update = xla.dynamic_update_slice(X_zeros, max_sample, [y_sample])\n", " X_sample = xla.dynamic_update_slice(X_sample, X_update, [0])\n", " return X_sample, y_sample\n", @@ -364,25 +370,23 @@ " @tf.function(reduce_retracing=True)\n", " def predict_one_sample(self, x):\n", " goodness_per_label = []\n", - " x = tf.reshape(x, [tf.shape(x)[0] * tf.shape(x)[1]])\n", + " x = ops.reshape(x, [ops.shape(x)[0] * ops.shape(x)[1]])\n", " for label in range(10):\n", " h, label = self.overlay_y_on_x(data=(x, label))\n", - " h = tf.reshape(h, [-1, tf.shape(h)[0]])\n", + " h = ops.reshape(h, [-1, ops.shape(h)[0]])\n", " goodness = []\n", " for layer_idx in range(1, len(self.layer_list)):\n", " layer = self.layer_list[layer_idx]\n", " h = layer(h)\n", - " goodness += [tf.math.reduce_mean(tf.math.pow(h, 2), 1)]\n", - " goodness_per_label += [\n", - " tf.expand_dims(tf.reduce_sum(goodness, keepdims=True), 1)\n", - " ]\n", + " goodness += [ops.mean(ops.power(h, 2), 1)]\n", + " goodness_per_label += [ops.expand_dims(ops.sum(goodness, keepdims=True), 1)]\n", " goodness_per_label = tf.concat(goodness_per_label, 1)\n", - " return tf.cast(tf.argmax(goodness_per_label, 1), tf.float64)\n", + " return ops.cast(ops.argmax(goodness_per_label, 1), dtype=\"float64\")\n", "\n", " def predict(self, data):\n", " x = data\n", " preds = list()\n", - " preds = tf.map_fn(fn=self.predict_one_sample, elems=x)\n", + " preds = ops.vectorized_map(self.predict_one_sample, x)\n", " return np.asarray(preds, dtype=int)\n", "\n", " # This custom `train_step` function overrides the internal `train_step`\n", @@ -395,17 +399,26 @@ " # the Forward-Forward computation on it. The returned loss is the final\n", " # loss value over all the layers.\n", "\n", - " @tf.function(jit_compile=True)\n", + " @tf.function(jit_compile=False)\n", " def train_step(self, data):\n", " x, y = data\n", "\n", + " if not self.metrics_built:\n", + " # build metrics to ensure they can be queried without erroring out.\n", + " # We can't update the metrics' state, as we would usually do, since\n", + " # we do not perform predictions within the train step\n", + " for metric in self.metrics:\n", + " if hasattr(metric, \"build\"):\n", + " metric.build(y, y)\n", + " self.metrics_built = True\n", + "\n", " # Flatten op\n", - " x = tf.reshape(x, [-1, tf.shape(x)[1] * tf.shape(x)[2]])\n", + " x = ops.reshape(x, [-1, ops.shape(x)[1] * ops.shape(x)[2]])\n", "\n", - " x_pos, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, y))\n", + " x_pos, y = ops.vectorized_map(self.overlay_y_on_x, (x, y))\n", "\n", " random_y = tf.random.shuffle(y)\n", - " x_neg, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, random_y))\n", + " x_neg, y = tf.map_fn(self.overlay_y_on_x, (x, random_y))\n", "\n", " h_pos, h_neg = x_pos, x_neg\n", "\n", @@ -418,8 +431,9 @@ " else:\n", " print(f\"Passing layer {idx+1} now : \")\n", " x = layer(x)\n", - " mean_res = tf.math.divide(self.loss_var, self.loss_count)\n", - " return {\"FinalLoss\": mean_res}\n" + " mean_res = ops.divide(self.loss_var, self.loss_count)\n", + " return {\"FinalLoss\": mean_res}\n", + "" ] }, { @@ -436,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, @@ -469,7 +483,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, @@ -480,8 +494,8 @@ "model.compile(\n", " optimizer=keras.optimizers.Adam(learning_rate=0.03),\n", " loss=\"mse\",\n", - " jit_compile=True,\n", - " metrics=[keras.metrics.Mean()],\n", + " jit_compile=False,\n", + " metrics=[],\n", ")\n", "\n", "epochs = 250\n", @@ -502,13 +516,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 0, "metadata": { "colab_type": "code" }, "outputs": [], "source": [ - "preds = model.predict(tf.convert_to_tensor(x_test))\n", + "preds = model.predict(ops.convert_to_tensor(x_test))\n", "\n", "preds = preds.reshape((preds.shape[0], preds.shape[1]))\n", "\n", @@ -577,4 +591,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file diff --git a/examples/vision/md/forwardforward.md b/examples/vision/md/forwardforward.md index 4fe88fd395..43c97d6166 100644 --- a/examples/vision/md/forwardforward.md +++ b/examples/vision/md/forwardforward.md @@ -2,7 +2,7 @@ **Author:** [Suvaditya Mukherjee](https://twitter.com/halcyonrayes)
**Date created:** 2023/01/08
-**Last modified:** 2023/01/08
+**Last modified:** 2024/09/17
**Description:** Training a Dense-layer model using the Forward-Forward algorithm. @@ -63,8 +63,13 @@ a primer on how to do so: ```python +import os + +os.environ["KERAS_BACKEND"] = "tensorflow" + import tensorflow as tf -from tensorflow import keras +import keras +from keras import ops import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import accuracy_score @@ -72,6 +77,7 @@ import random from tensorflow.compiler.tf2xla.python import xla ``` + --- ## Load the dataset and visualize the data @@ -108,13 +114,13 @@ plt.show()
``` -Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz -11490434/11490434 [==============================] - 0s 0us/step 4 Random Training samples and labels ```
+ ![png](/img/examples/vision/forwardforward/forwardforward_5_1.png) + --- @@ -161,7 +167,7 @@ class FFDense(keras.layers.Layer): def __init__( self, units, - optimizer, + init_optimizer, loss_metric, num_epochs=50, use_bias=True, @@ -181,7 +187,7 @@ class FFDense(keras.layers.Layer): bias_regularizer=bias_regularizer, ) self.relu = keras.layers.ReLU() - self.optimizer = optimizer + self.optimizer = init_optimizer() self.loss_metric = loss_metric self.threshold = 1.5 self.num_epochs = num_epochs @@ -190,7 +196,7 @@ class FFDense(keras.layers.Layer): # layer. def call(self, x): - x_norm = tf.norm(x, ord=2, axis=1, keepdims=True) + x_norm = ops.norm(x, ord=2, axis=1, keepdims=True) x_norm = x_norm + 1e-4 x_dir = x / x_norm res = self.dense(x_dir) @@ -210,22 +216,24 @@ class FFDense(keras.layers.Layer): def forward_forward(self, x_pos, x_neg): for i in range(self.num_epochs): with tf.GradientTape() as tape: - g_pos = tf.math.reduce_mean(tf.math.pow(self.call(x_pos), 2), 1) - g_neg = tf.math.reduce_mean(tf.math.pow(self.call(x_neg), 2), 1) + g_pos = ops.mean(ops.power(self.call(x_pos), 2), 1) + g_neg = ops.mean(ops.power(self.call(x_neg), 2), 1) - loss = tf.math.log( + loss = ops.log( 1 - + tf.math.exp( - tf.concat([-g_pos + self.threshold, g_neg - self.threshold], 0) + + ops.exp( + ops.concatenate( + [-g_pos + self.threshold, g_neg - self.threshold], 0 + ) ) ) - mean_loss = tf.cast(tf.math.reduce_mean(loss), tf.float32) + mean_loss = ops.cast(ops.mean(loss), dtype="float32") self.loss_metric.update_state([mean_loss]) gradients = tape.gradient(mean_loss, self.dense.trainable_weights) self.optimizer.apply_gradients(zip(gradients, self.dense.trainable_weights)) return ( - tf.stop_gradient(self.call(x_pos)), - tf.stop_gradient(self.call(x_neg)), + ops.stop_gradient(self.call(x_pos)), + ops.stop_gradient(self.call(x_neg)), self.loss_metric.result(), ) @@ -268,25 +276,24 @@ class FFNetwork(keras.Model): # the `Adam` optimizer with a default learning rate of 0.03 as that was # found to be the best rate after experimentation. # Loss is tracked using `loss_var` and `loss_count` variables. - # Use legacy optimizer for Layer Optimizer to fix issue - # https://github.com/keras-team/keras-io/issues/1241 def __init__( self, dims, - layer_optimizer=keras.optimizers.legacy.Adam(learning_rate=0.03), + init_layer_optimizer=lambda: keras.optimizers.Adam(learning_rate=0.03), **kwargs, ): super().__init__(**kwargs) - self.layer_optimizer = layer_optimizer - self.loss_var = tf.Variable(0.0, trainable=False, dtype=tf.float32) - self.loss_count = tf.Variable(0.0, trainable=False, dtype=tf.float32) + self.init_layer_optimizer = init_layer_optimizer + self.loss_var = keras.Variable(0.0, trainable=False, dtype="float32") + self.loss_count = keras.Variable(0.0, trainable=False, dtype="float32") self.layer_list = [keras.Input(shape=(dims[0],))] + self.metrics_built = False for d in range(len(dims) - 1): self.layer_list += [ FFDense( dims[d + 1], - optimizer=self.layer_optimizer, + init_optimizer=self.init_layer_optimizer, loss_metric=keras.metrics.Mean(), ) ] @@ -300,9 +307,9 @@ class FFNetwork(keras.Model): @tf.function(reduce_retracing=True) def overlay_y_on_x(self, data): X_sample, y_sample = data - max_sample = tf.reduce_max(X_sample, axis=0, keepdims=True) - max_sample = tf.cast(max_sample, dtype=tf.float64) - X_zeros = tf.zeros([10], dtype=tf.float64) + max_sample = ops.amax(X_sample, axis=0, keepdims=True) + max_sample = ops.cast(max_sample, dtype="float64") + X_zeros = ops.zeros([10], dtype="float64") X_update = xla.dynamic_update_slice(X_zeros, max_sample, [y_sample]) X_sample = xla.dynamic_update_slice(X_sample, X_update, [0]) return X_sample, y_sample @@ -317,25 +324,23 @@ class FFNetwork(keras.Model): @tf.function(reduce_retracing=True) def predict_one_sample(self, x): goodness_per_label = [] - x = tf.reshape(x, [tf.shape(x)[0] * tf.shape(x)[1]]) + x = ops.reshape(x, [ops.shape(x)[0] * ops.shape(x)[1]]) for label in range(10): h, label = self.overlay_y_on_x(data=(x, label)) - h = tf.reshape(h, [-1, tf.shape(h)[0]]) + h = ops.reshape(h, [-1, ops.shape(h)[0]]) goodness = [] for layer_idx in range(1, len(self.layer_list)): layer = self.layer_list[layer_idx] h = layer(h) - goodness += [tf.math.reduce_mean(tf.math.pow(h, 2), 1)] - goodness_per_label += [ - tf.expand_dims(tf.reduce_sum(goodness, keepdims=True), 1) - ] + goodness += [ops.mean(ops.power(h, 2), 1)] + goodness_per_label += [ops.expand_dims(ops.sum(goodness, keepdims=True), 1)] goodness_per_label = tf.concat(goodness_per_label, 1) - return tf.cast(tf.argmax(goodness_per_label, 1), tf.float64) + return ops.cast(ops.argmax(goodness_per_label, 1), dtype="float64") def predict(self, data): x = data preds = list() - preds = tf.map_fn(fn=self.predict_one_sample, elems=x) + preds = ops.vectorized_map(self.predict_one_sample, x) return np.asarray(preds, dtype=int) # This custom `train_step` function overrides the internal `train_step` @@ -348,17 +353,26 @@ class FFNetwork(keras.Model): # the Forward-Forward computation on it. The returned loss is the final # loss value over all the layers. - @tf.function(jit_compile=True) + @tf.function(jit_compile=False) def train_step(self, data): x, y = data + if not self.metrics_built: + # build metrics to ensure they can be queried without erroring out. + # We can't update the metrics' state, as we would usually do, since + # we do not perform predictions within the train step + for metric in self.metrics: + if hasattr(metric, "build"): + metric.build(y, y) + self.metrics_built = True + # Flatten op - x = tf.reshape(x, [-1, tf.shape(x)[1] * tf.shape(x)[2]]) + x = ops.reshape(x, [-1, ops.shape(x)[1] * ops.shape(x)[2]]) - x_pos, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, y)) + x_pos, y = ops.vectorized_map(self.overlay_y_on_x, (x, y)) random_y = tf.random.shuffle(y) - x_neg, y = tf.map_fn(fn=self.overlay_y_on_x, elems=(x, random_y)) + x_neg, y = tf.map_fn(self.overlay_y_on_x, (x, random_y)) h_pos, h_neg = x_pos, x_neg @@ -371,7 +385,7 @@ class FFNetwork(keras.Model): else: print(f"Passing layer {idx+1} now : ") x = layer(x) - mean_res = tf.math.divide(self.loss_var, self.loss_count) + mean_res = ops.divide(self.loss_var, self.loss_count) return {"FinalLoss": mean_res} ``` @@ -396,6 +410,7 @@ train_dataset = train_dataset.batch(60000) test_dataset = test_dataset.batch(10000) ``` + --- ## Fit the network and visualize results @@ -410,8 +425,8 @@ model = FFNetwork(dims=[784, 500, 500]) model.compile( optimizer=keras.optimizers.Adam(learning_rate=0.03), loss="mse", - jit_compile=True, - metrics=[keras.metrics.Mean()], + jit_compile=False, + metrics=[], ) epochs = 250 @@ -421,512 +436,766 @@ history = model.fit(train_dataset, epochs=epochs)
``` Epoch 1/250 + Training layer 1 now : + Training layer 2 now : + Training layer 1 now : + Training layer 2 now : -1/1 [==============================] - 72s 72s/step - FinalLoss: 0.7279 +1/1 ━━━━━━━━━━━━━━━━━━━━ 90s 90s/step - FinalLoss: 0.7247 + Epoch 2/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.7082 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.7089 + Epoch 3/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.7031 + 1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.6978 + Epoch 4/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.6806 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.6827 + Epoch 5/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.6564 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.6644 + Epoch 6/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.6333 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.6462 + Epoch 7/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.6126 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.6290 + Epoch 8/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5946 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.6131 + Epoch 9/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5786 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5986 + Epoch 10/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5644 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5853 + Epoch 11/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5518 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5731 + Epoch 12/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5405 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5621 + Epoch 13/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5301 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5519 + Epoch 14/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5207 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5425 + Epoch 15/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.5122 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5338 + Epoch 16/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.5044 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5259 + Epoch 17/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4972 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5186 + Epoch 18/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4906 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5117 + Epoch 19/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4845 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.5052 + Epoch 20/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4787 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4992 + Epoch 21/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4734 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4935 + Epoch 22/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4685 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4883 + Epoch 23/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4639 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4833 + Epoch 24/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4596 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4786 + Epoch 25/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4555 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4741 + Epoch 26/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4516 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4698 + Epoch 27/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4479 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4658 + Epoch 28/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4445 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4620 + Epoch 29/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4411 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4584 + Epoch 30/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4380 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4550 + Epoch 31/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4350 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4517 + Epoch 32/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4322 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4486 + Epoch 33/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4295 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4456 + Epoch 34/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4269 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4429 + Epoch 35/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4245 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4401 + Epoch 36/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4222 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4375 + Epoch 37/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4199 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4350 + Epoch 38/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4178 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4325 + Epoch 39/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4157 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4302 + Epoch 40/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4136 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4279 + Epoch 41/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4117 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4258 + Epoch 42/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4098 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4236 + Epoch 43/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4079 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4216 + Epoch 44/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4062 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4197 + Epoch 45/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4045 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4177 + Epoch 46/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4028 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4159 + Epoch 47/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.4012 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4141 + Epoch 48/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3996 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4124 + Epoch 49/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3982 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4107 + Epoch 50/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3967 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4090 + Epoch 51/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3952 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4074 + Epoch 52/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3938 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4059 + Epoch 53/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3925 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4044 + Epoch 54/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3912 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.4030 + Epoch 55/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3899 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4016 + Epoch 56/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3886 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.4002 + Epoch 57/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3874 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3988 + Epoch 58/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3862 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3975 + Epoch 59/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3851 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3962 + Epoch 60/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3840 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3950 + Epoch 61/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3829 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3938 + Epoch 62/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3818 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3926 + Epoch 63/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3807 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3914 + Epoch 64/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3797 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3903 + Epoch 65/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3787 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3891 + Epoch 66/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3777 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3880 + Epoch 67/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3767 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3869 + Epoch 68/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3758 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3859 + Epoch 69/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3748 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3849 + Epoch 70/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3739 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3839 + Epoch 71/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3730 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3829 + Epoch 72/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3721 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3819 + Epoch 73/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3712 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3810 + Epoch 74/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3704 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3801 + Epoch 75/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3695 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3792 + Epoch 76/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3688 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3783 + Epoch 77/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3680 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3774 + Epoch 78/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3671 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3765 + Epoch 79/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3664 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3757 + Epoch 80/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3656 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3748 + Epoch 81/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3648 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3740 + Epoch 82/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3641 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3732 + Epoch 83/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3634 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3723 + Epoch 84/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3627 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3715 + Epoch 85/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3620 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3708 + Epoch 86/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3613 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3700 + Epoch 87/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3606 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3692 + Epoch 88/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3599 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3685 + Epoch 89/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3593 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3677 + Epoch 90/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3586 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3670 + Epoch 91/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3580 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3663 + Epoch 92/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3574 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3656 + Epoch 93/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3568 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3649 + Epoch 94/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3561 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3642 + Epoch 95/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3555 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3635 + Epoch 96/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3549 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3629 + Epoch 97/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3544 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3622 + Epoch 98/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3538 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3616 + Epoch 99/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3532 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3610 + Epoch 100/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3526 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3603 + Epoch 101/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3521 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3597 + Epoch 102/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3515 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3591 + Epoch 103/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3510 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3585 + Epoch 104/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3505 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3579 + Epoch 105/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3499 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3573 + Epoch 106/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3494 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3567 + Epoch 107/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3489 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3562 + Epoch 108/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3484 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3556 + Epoch 109/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3478 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3550 + Epoch 110/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3474 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3545 + Epoch 111/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3468 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3539 + Epoch 112/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3464 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3534 + Epoch 113/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3459 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3529 + Epoch 114/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3454 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3524 + Epoch 115/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3450 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3519 + Epoch 116/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3445 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3513 + Epoch 117/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3440 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3508 + Epoch 118/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3436 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3503 + Epoch 119/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3432 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3498 + Epoch 120/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3427 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3493 + Epoch 121/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3423 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3488 + Epoch 122/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3419 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3484 + Epoch 123/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3414 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3479 + Epoch 124/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3410 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3474 + Epoch 125/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3406 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3470 + Epoch 126/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3402 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3465 + Epoch 127/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3398 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3461 + Epoch 128/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3394 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3456 + Epoch 129/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3390 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3452 + Epoch 130/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3386 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3447 + Epoch 131/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3382 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3443 + Epoch 132/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3378 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3439 + Epoch 133/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3375 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3435 + Epoch 134/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3371 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3430 + Epoch 135/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3368 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3426 + Epoch 136/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3364 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3422 + Epoch 137/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3360 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3418 + Epoch 138/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3357 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3414 + Epoch 139/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3353 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3411 + Epoch 140/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3350 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3407 + Epoch 141/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3346 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3403 + Epoch 142/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3343 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3399 + Epoch 143/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3339 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3395 + Epoch 144/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3336 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3391 + Epoch 145/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3333 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3387 + Epoch 146/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3329 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3384 + Epoch 147/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3326 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3380 + Epoch 148/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3323 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3376 + Epoch 149/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3320 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3373 + Epoch 150/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3317 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3369 + Epoch 151/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3313 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3366 + Epoch 152/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3310 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3362 + Epoch 153/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3307 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3359 + Epoch 154/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3304 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3355 + Epoch 155/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3302 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3352 + Epoch 156/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3299 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3349 + Epoch 157/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3296 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3346 + Epoch 158/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3293 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3342 + Epoch 159/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3290 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3339 + Epoch 160/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3287 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3336 + Epoch 161/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3284 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3333 + Epoch 162/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3281 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3330 + Epoch 163/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3279 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3327 + Epoch 164/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3276 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3324 + Epoch 165/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3273 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3321 + Epoch 166/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3270 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3318 + Epoch 167/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3268 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3315 + Epoch 168/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3265 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3312 + Epoch 169/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3262 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3309 + Epoch 170/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3260 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3306 + Epoch 171/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3257 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3303 + Epoch 172/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3255 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3301 + Epoch 173/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3252 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3298 + Epoch 174/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3250 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3295 + Epoch 175/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3247 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3292 + Epoch 176/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3244 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3289 + Epoch 177/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3242 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3287 + Epoch 178/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3240 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3284 + Epoch 179/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3237 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3281 + Epoch 180/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3235 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3279 + Epoch 181/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3232 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3276 + Epoch 182/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3230 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3273 + Epoch 183/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3228 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3271 + Epoch 184/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3225 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3268 + Epoch 185/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3223 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3266 + Epoch 186/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3221 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3263 + Epoch 187/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3219 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3261 + Epoch 188/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3216 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3259 + Epoch 189/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3214 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3256 + Epoch 190/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3212 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3254 + Epoch 191/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3210 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3251 + Epoch 192/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3208 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3249 + Epoch 193/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3205 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3247 + Epoch 194/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3203 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3244 + Epoch 195/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3201 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3242 + Epoch 196/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3199 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3240 + Epoch 197/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3197 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3238 + Epoch 198/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3195 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3235 + Epoch 199/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3193 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3233 + Epoch 200/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3191 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3231 + Epoch 201/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3189 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3228 + Epoch 202/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3187 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3226 + Epoch 203/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3185 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3224 + Epoch 204/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3183 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3222 + Epoch 205/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3181 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3220 + Epoch 206/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3179 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3217 + Epoch 207/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3177 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3215 + Epoch 208/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3175 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3213 + Epoch 209/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3174 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3211 + Epoch 210/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3172 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3209 + Epoch 211/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3170 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3207 + Epoch 212/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3168 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3205 + Epoch 213/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3166 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3203 + Epoch 214/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3165 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3201 + Epoch 215/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3163 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3199 + Epoch 216/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3161 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3197 + Epoch 217/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3159 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3195 + Epoch 218/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3157 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3193 + Epoch 219/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3155 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3191 + Epoch 220/250 -1/1 [==============================] - 5s 5s/step - FinalLoss: 0.3154 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3190 + Epoch 221/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3152 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3188 + Epoch 222/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3150 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3186 + Epoch 223/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3148 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3184 + Epoch 224/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3147 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3182 + Epoch 225/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3145 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3180 + Epoch 226/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3143 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3179 + Epoch 227/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3142 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3177 + Epoch 228/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3140 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3175 + Epoch 229/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3139 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3173 + Epoch 230/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3137 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3171 + Epoch 231/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3135 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3170 + Epoch 232/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3134 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3168 + Epoch 233/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3132 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3166 + Epoch 234/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3131 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3164 + Epoch 235/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3129 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3163 + Epoch 236/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3127 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3161 + Epoch 237/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3126 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3159 + Epoch 238/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3124 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3158 + Epoch 239/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3123 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3156 + Epoch 240/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3121 +1/1 ━━━━━━━━━━━━━━━━━━━━ 41s 41s/step - FinalLoss: 0.3154 + Epoch 241/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3120 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3152 + Epoch 242/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3118 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3151 + Epoch 243/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3117 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3149 + Epoch 244/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3116 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3148 + Epoch 245/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3114 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3146 + Epoch 246/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3113 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3145 + Epoch 247/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3111 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3143 + Epoch 248/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3110 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3141 + Epoch 249/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3108 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3140 + Epoch 250/250 -1/1 [==============================] - 6s 6s/step - FinalLoss: 0.3107 +1/1 ━━━━━━━━━━━━━━━━━━━━ 40s 40s/step - FinalLoss: 0.3138 ```
+ --- ## Perform inference and testing @@ -935,7 +1204,7 @@ test set. We calculate the Accuracy Score to understand the results closely. ```python -preds = model.predict(tf.convert_to_tensor(x_test)) +preds = model.predict(ops.convert_to_tensor(x_test)) preds = preds.reshape((preds.shape[0], preds.shape[1])) @@ -950,11 +1219,13 @@ plt.show()
``` -Test Accuracy score : 97.64% +Test Accuracy score : 97.56% ```
+ ![png](/img/examples/vision/forwardforward/forwardforward_15_1.png) + ---