You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
" <img src=\"https://i.ibb.co/xfJbPmL/github.png\" height=\"70px\" style=\"padding-bottom:5px;\" />View Source on GitHub</a></td>\n",
17
17
"</table>\n",
18
18
"\n",
@@ -28,8 +28,8 @@
28
28
},
29
29
"outputs": [],
30
30
"source": [
31
-
"# Copyright 2023 MIT Introduction to Deep Learning. All Rights Reserved.\n",
32
-
"#\n",
31
+
"# Copyright 2024 MIT Introduction to Deep Learning. All Rights Reserved.\n",
32
+
"#\n",
33
33
"# Licensed under the MIT License. You may not use this file except in compliance\n",
34
34
"# with the License. Use and/or modification of this code outside of MIT Introduction\n",
35
35
"# to Deep Learning must reference:\n",
@@ -65,41 +65,16 @@
65
65
},
66
66
"outputs": [],
67
67
"source": [
68
-
"%tensorflow_version 2.x\n",
69
68
"import tensorflow as tf\n",
70
69
"\n",
71
70
"# Download and import the MIT Introduction to Deep Learning package\n",
72
-
"!pip install mitdeeplearning\n",
71
+
"!pip install mitdeeplearning --quiet\n",
73
72
"import mitdeeplearning as mdl\n",
74
73
"\n",
75
74
"import numpy as np\n",
76
75
"import matplotlib.pyplot as plt"
77
76
]
78
77
},
79
-
{
80
-
"cell_type": "markdown",
81
-
"metadata": {},
82
-
"source": [
83
-
"## 0.2 Set Up Comet\n",
84
-
"\n",
85
-
"When training models, it can be useful to visualize information about the model with plots. We can do this manually, but here, we'll show you how to do this using a tool called Comet, which generates loss and GPU usage curves for you.\n",
86
-
"\n",
87
-
"First, sign up for a Comet account [at this link](https://www.comet.com/signup?utm_source=mit_dl&utm_medium=partner&utm_content=github\n",
88
-
") (you can use your Google or Github account). Running this cell will prompt you to enter your API Key (which you can find by pressing the '?' in the top right corner and then 'Quickstart Guide' - it is on the right hand side of the page)."
"# Use tf.zeros to initialize a 4-d Tensor of zeros with size 10 x 256 x 256 x 3.\n",
167
+
"# Use tf.zeros to initialize a 4-d Tensor of zeros with size 10 x 256 x 256 x 3.\n",
193
168
"# You can think of this as 10 images where each image is RGB 256 x 256.\n",
194
169
"images = # TODO\n",
195
170
"\n",
@@ -335,7 +310,7 @@
335
310
"## 1.3 Neural networks in TensorFlow\n",
336
311
"We can also define neural networks in TensorFlow. TensorFlow uses a high-level API called [Keras](https://www.tensorflow.org/guide/keras) that provides a powerful, intuitive framework for building and training deep learning models.\n",
337
312
"\n",
338
-
"Let's first consider the example of a simple perceptron defined by just one dense layer: $ y = \\sigma(Wx + b)$, where $W$ represents a matrix of weights, $b$ is a bias, $x$ is the input, $\\sigma$ is the sigmoid activation function, and $y$ is the output. We can also visualize this operation using a graph:\n",
313
+
"Let's first consider the example of a simple perceptron defined by just one dense layer: $ y = \\sigma(Wx + b)$, where $W$ represents a matrix of weights, $b$ is a bias, $x$ is the input, $\\sigma$ is the sigmoid activation function, and $y$ is the output. We can also visualize this operation using a graph:\n",
"Conveniently, TensorFlow has defined a number of ```Layers``` that are commonly used in neural networks, for example a [```Dense```](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense?version=stable). Now, instead of using a single ```Layer``` to define our simple neural network, we'll use the [`Sequential`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/Sequential) model from Keras and a single [`Dense` ](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/layers/Dense) layer to define our network. With the `Sequential` API, you can readily create neural networks by stacking together layers like building blocks."
372
+
"Conveniently, TensorFlow has defined a number of ```Layers``` that are commonly used in neural networks, for example a [```Dense```](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense?version=stable). Now, instead of using a single ```Layer``` to define our simple neural network, we'll use the [`Sequential`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/Sequential) model from Keras and a single [`Dense` ](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/keras/layers/Dense) layer to define our network. With the `Sequential` API, you can readily create neural networks by stacking together layers like building blocks."
398
373
]
399
374
},
400
375
{
@@ -414,12 +389,12 @@
414
389
"# Define the number of outputs\n",
415
390
"n_output_nodes = 3\n",
416
391
"\n",
417
-
"# First define the model\n",
392
+
"# First define the model\n",
418
393
"model = Sequential()\n",
419
394
"\n",
420
395
"'''TODO: Define a dense (fully connected) layer to compute z'''\n",
421
396
"# Remember: dense layers are defined by the parameters W and b!\n",
422
-
"# You can read more about the initialization of W and b in the TF documentation :)\n",
397
+
"# You can read more about the initialization of W and b in the TF documentation :)\n",
"is one of the most important parts of TensorFlow and is the backbone of training with\n",
600
-
"[backpropagation](https://en.wikipedia.org/wiki/Backpropagation). We will use the TensorFlow GradientTape [`tf.GradientTape`](https://www.tensorflow.org/api_docs/python/tf/GradientTape?version=stable) to trace operations for computing gradients later.\n",
574
+
"is one of the most important parts of TensorFlow and is the backbone of training with\n",
575
+
"[backpropagation](https://en.wikipedia.org/wiki/Backpropagation). We will use the TensorFlow GradientTape [`tf.GradientTape`](https://www.tensorflow.org/api_docs/python/tf/GradientTape?version=stable) to trace operations for computing gradients later.\n",
601
576
"\n",
602
577
"When a forward pass is made through the network, all forward-pass operations get recorded to a \"tape\"; then, to compute the gradient, the tape is played backwards. By default, the tape is discarded after it is played backwards; this means that a particular `tf.GradientTape` can only\n",
603
-
"compute one gradient, and subsequent calls throw a runtime error. However, we can compute multiple gradients over the same computation by creating a ```persistent``` gradient tape.\n",
578
+
"compute one gradient, and subsequent calls throw a runtime error. However, we can compute multiple gradients over the same computation by creating a ```persistent``` gradient tape.\n",
604
579
"\n",
605
580
"First, we will look at how we can compute gradients using GradientTape and access them for computation. We define the simple function $ y = x^2$ and compute the gradient:"
606
581
]
@@ -663,14 +638,13 @@
663
638
"# Define the target value\n",
664
639
"x_f = 4\n",
665
640
"\n",
666
-
"# We will run SGD for a number of iterations. At each iteration, we compute the loss,\n",
641
+
"# We will run SGD for a number of iterations. At each iteration, we compute the loss,\n",
667
642
"# compute the derivative of the loss with respect to x, and perform the SGD update.\n",
668
643
"for i in range(500):\n",
669
644
" with tf.GradientTape() as tape:\n",
670
645
" '''TODO: define the loss as described above'''\n",
0 commit comments