Skip to content

Commit 55e5c48

Browse files
committed
making todos face detection
1 parent 0e251c8 commit 55e5c48

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

lab2/Part2_FaceDetection.ipynb

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
" <td align=\"center\"><a target=\"_blank\" href=\"http://introtodeeplearning.com\">\n",
1111
" <img src=\"https://i.ibb.co/Jr88sn2/mit.png\" style=\"padding-bottom:5px;\" />\n",
1212
" Visit MIT Deep Learning</a></td>\n",
13-
" <td align=\"center\"><a target=\"_blank\" href=\"https://colab.research.google.com/github/aamini/introtodeeplearning/blob/2023/lab2/Part2_FaceDetection.ipynb\">\n",
13+
" <td align=\"center\"><a target=\"_blank\" href=\"https://colab.research.google.com/github/aamini/introtodeeplearning/blob/2023/lab2/solutions/Part2_FaceDetection_Solution.ipynb\">\n",
1414
" <img src=\"https://i.ibb.co/2P3SLwK/colab.png\" style=\"padding-bottom:5px;\" />Run in Google Colab</a></td>\n",
15-
" <td align=\"center\"><a target=\"_blank\" href=\"https://github.com/aamini/introtodeeplearning/blob/2023/lab2/Part2_FaceDetection.ipynb\">\n",
15+
" <td align=\"center\"><a target=\"_blank\" href=\"https://github.com/aamini/introtodeeplearning/blob/2023/lab2/solutions/Part2_FaceDetection_Solution.ipynb\">\n",
1616
" <img src=\"https://i.ibb.co/xfJbPmL/github.png\" height=\"70px\" style=\"padding-bottom:5px;\" />View Source on GitHub</a></td>\n",
1717
"</table>\n",
1818
"\n",
@@ -435,22 +435,19 @@
435435
"def vae_loss_function(x, x_recon, mu, logsigma, kl_weight=0.0005):\n",
436436
" # TODO: Define the latent loss. Note this is given in the equation for L_{KL}\n",
437437
" # in the text block directly above\n",
438-
" latent_loss = 0.5 * tf.reduce_sum(tf.exp(logsigma) + tf.square(mu) - 1.0 - logsigma, axis=1)\n",
439-
" # latent_loss = # TODO\n",
438+
" latent_loss = # TODO\n",
440439
"\n",
441440
" # TODO: Define the reconstruction loss as the mean absolute pixel-wise \n",
442441
" # difference between the input and reconstruction. Hint: you'll need to \n",
443442
" # use tf.reduce_mean, and supply an axis argument which specifies which \n",
444443
" # dimensions to reduce over. For example, reconstruction loss needs to average \n",
445444
" # over the height, width, and channel image dimensions.\n",
446445
" # https://www.tensorflow.org/api_docs/python/tf/math/reduce_mean\n",
447-
" reconstruction_loss = tf.reduce_mean(tf.abs(x-x_recon), axis=(1,2,3))\n",
448-
" # reconstruction_loss = # TODO\n",
446+
" reconstruction_loss = # TODO\n",
449447
"\n",
450448
" # TODO: Define the VAE loss. Note this is given in the equation for L_{VAE}\n",
451449
" # in the text block directly above\n",
452-
" vae_loss = kl_weight * latent_loss + reconstruction_loss\n",
453-
" # vae_loss = # TODO\n",
450+
" vae_loss = # TODO\n",
454451
" \n",
455452
" return vae_loss"
456453
]
@@ -495,8 +492,8 @@
495492
"\n",
496493
" # TODO: Define the reparameterization computation!\n",
497494
" # Note the equation is given in the text block immediately above.\n",
498-
" z = z_mean + tf.math.exp(0.5 * z_logsigma) * epsilon\n",
499-
" # z = # TODO\n",
495+
" z = # TODO\n",
496+
" \n",
500497
" return z"
501498
]
502499
},
@@ -588,25 +585,19 @@
588585
"def ss_vae_loss_function(x, x_pred, y, y_logit, mu, logsigma):\n",
589586
"\n",
590587
" # TODO: call the relevant function to obtain VAE loss, defined earlier in the lab\n",
591-
" vae_loss = vae_loss_function(x, x_pred, mu, logsigma)\n",
592-
" # vae_loss = vae_loss_function('''TODO''') # TODO\n",
588+
" vae_loss = vae_loss_function('''TODO''') # TODO\n",
593589
"\n",
594590
" # TODO: define the classification loss using sigmoid_cross_entropy\n",
595591
" # https://www.tensorflow.org/api_docs/python/tf/nn/sigmoid_cross_entropy_with_logits\n",
596-
" classification_loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=y, logits=y_logit)\n",
597-
" # classification_loss = # TODO\n",
592+
" classification_loss = # TODO\n",
598593
"\n",
599594
" # Use the training data labels to create variable face_indicator:\n",
600595
" # indicator that reflects which training data are images of faces\n",
601596
" face_indicator = tf.cast(tf.equal(y, 1), tf.float32)\n",
602597
"\n",
603598
" # TODO: define the SS-VAE total loss! Use tf.reduce_mean to average over all\n",
604599
" # samples\n",
605-
" total_loss = tf.reduce_mean(\n",
606-
" classification_loss + \n",
607-
" face_indicator * vae_loss\n",
608-
" )\n",
609-
" # total_loss = # TODO\n",
600+
" total_loss = # TODO\n",
610601
"\n",
611602
" return total_loss, classification_loss, vae_loss"
612603
]
@@ -708,8 +699,7 @@
708699
" # Decode the latent space and output reconstruction\n",
709700
" def decode(self, z):\n",
710701
" # TODO: use the decoder (self.decoder) to output the reconstruction\n",
711-
" reconstruction = self.decoder(z)\n",
712-
" # reconstruction = # TODO\n",
702+
" reconstruction = # TODO\n",
713703
" return reconstruction\n",
714704
"\n",
715705
" # The call function will be used to pass inputs x through the core VAE\n",
@@ -719,12 +709,11 @@
719709
"\n",
720710
" # TODO: call the sampling function that you created above using \n",
721711
" # z_mean and z_logsigma\n",
722-
" z = sampling(z_mean, z_logsigma)\n",
723-
" # z = # TODO\n",
712+
" z = # TODO\n",
724713
"\n",
725714
" # TODO: reconstruction\n",
726-
" recon = self.decode(z)\n",
727-
" # recon = # TODO\n",
715+
" recon = # TODO\n",
716+
" \n",
728717
" return y_logit, z_mean, z_logsigma, recon\n",
729718
"\n",
730719
" # Predict face or not face logit for given input x\n",
@@ -789,13 +778,11 @@
789778
" y_logit, z_mean, z_logsigma, x_recon = ss_vae(x)\n",
790779
"\n",
791780
" '''TODO: call the SS_VAE loss function to compute the loss'''\n",
792-
" loss, class_loss, _ = ss_vae_loss_function(x, x_recon, y, y_logit, z_mean, z_logsigma)\n",
793-
" # loss, class_loss = ss_vae_loss_function('''TODO arguments''') # TODO\n",
781+
" loss, class_loss = ss_vae_loss_function('''TODO arguments''') # TODO\n",
794782
" \n",
795783
" '''TODO: use the GradientTape.gradient method to compute the gradients.\n",
796784
" Hint: this is with respect to the trainable_variables of the SS_VAE.'''\n",
797-
" grads = tape.gradient(loss, ss_vae.trainable_variables)\n",
798-
" # grads = tape.gradient('''TODO''', '''TODO''') # TODO\n",
785+
" grads = tape.gradient('''TODO''', '''TODO''') # TODO\n",
799786
"\n",
800787
" # apply gradients to variables\n",
801788
" optimizer.apply_gradients(zip(grads, ss_vae.trainable_variables))\n",

0 commit comments

Comments
 (0)