Skip to content

Commit 795b077

Browse files
committed
Fix: use add_weight instead of tf.Variable in training loop guide
1 parent 820135c commit 795b077

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

site/en/guide/basic_training_loops.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@
212212
" super().__init__(**kwargs)\n",
213213
" # Initialize the weights to `5.0` and the bias to `0.0`\n",
214214
" # In practice, these should be randomly initialized\n",
215-
" self.w = tf.Variable(5.0)\n",
216-
" self.b = tf.Variable(0.0)\n",
215+
" self.w = self.add_weight(name='w', shape=(), initializer=tf.constant_initializer(5.0))\n",
216+
" self.b = self.add_weight(name='b', shape=(), initializer=tf.constant_initializer(0.0))\n",
217+
"\n",
218+
" # Use add_weight so Keras can track this as a trainable weight\n",
217219
"\n",
218220
" def __call__(self, x):\n",
219221
" return self.w * x + self.b\n",

0 commit comments

Comments
 (0)