Skip to content

Commit f4095df

Browse files
Shorna AlamShorna Alam
authored andcommitted
final fixes for lab2part1 (image logging on comet)
1 parent 2215368 commit f4095df

File tree

4 files changed

+89
-474
lines changed

4 files changed

+89
-474
lines changed

lab2/Part1_MNIST.ipynb

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,23 @@
6161
},
6262
"outputs": [],
6363
"source": [
64-
"#Import Comet\n",
65-
"%pip install comet_ml\n",
66-
"import comet_ml\n",
67-
"comet_ml.init(project_name=\"6.s191lab2.1.1\")\n",
68-
"comet_model_1 = comet_ml.Experiment()\n",
69-
"\n",
7064
"# Import Tensorflow 2.0\n",
7165
"%tensorflow_version 2.x\n",
7266
"import tensorflow as tf \n",
7367
"\n",
7468
"!pip install mitdeeplearning\n",
7569
"import mitdeeplearning as mdl\n",
7670
"\n",
71+
"#Import Comet\n",
72+
"!pip install comet_ml\n",
73+
"import comet_ml\n",
74+
"comet_ml.init(project_name=\"6.s191lab2_part1_NN\")\n",
75+
"comet_model_1 = comet_ml.Experiment()\n",
76+
"\n",
7777
"import matplotlib.pyplot as plt\n",
7878
"import numpy as np\n",
7979
"import random\n",
80-
"from tqdm import tqdm\n",
81-
"\n",
82-
"# Check that we are using a GPU, if not switch runtimes\n",
83-
"# using Runtime > Change Runtime Type > GPU\n",
84-
"assert len(tf.config.list_physical_devices('GPU')) > 0"
80+
"from tqdm import tqdm"
8581
]
8682
},
8783
{
@@ -421,7 +417,7 @@
421417
},
422418
"outputs": [],
423419
"source": [
424-
"comet_ml.init(project_name=\"6.s191lab2.1.2\")\n",
420+
"comet_ml.init(project_name=\"6.s191lab2_part1_CNN\")\n",
425421
"comet_model_2 = comet_ml.Experiment()\n",
426422
"\n",
427423
"'''TODO: Define the compile operation with your optimizer and learning rate of choice'''\n",
@@ -568,7 +564,8 @@
568564
"outputs": [],
569565
"source": [
570566
"print(\"Label of this digit is:\", test_labels[0])\n",
571-
"plt.imshow(test_images[0,:,:,0], cmap=plt.cm.binary)"
567+
"plt.imshow(test_images[0,:,:,0], cmap=plt.cm.binary)\n",
568+
"comet_model_2.log_figure(figure=plt)"
572569
]
573570
},
574571
{
@@ -594,7 +591,8 @@
594591
"plt.subplot(1,2,1)\n",
595592
"mdl.lab2.plot_image_prediction(image_index, predictions, test_labels, test_images)\n",
596593
"plt.subplot(1,2,2)\n",
597-
"mdl.lab2.plot_value_prediction(image_index, predictions, test_labels)"
594+
"mdl.lab2.plot_value_prediction(image_index, predictions, test_labels)\n",
595+
"comet_model_2.log_figure(figure=plt)"
598596
]
599597
},
600598
{
@@ -624,7 +622,9 @@
624622
" plt.subplot(num_rows, 2*num_cols, 2*i+1)\n",
625623
" mdl.lab2.plot_image_prediction(i, predictions, test_labels, test_images)\n",
626624
" plt.subplot(num_rows, 2*num_cols, 2*i+2)\n",
627-
" mdl.lab2.plot_value_prediction(i, predictions, test_labels)\n"
625+
" mdl.lab2.plot_value_prediction(i, predictions, test_labels)\n",
626+
"comet_model_2.log_figure(figure=plt)\n",
627+
"comet_model_2.end()"
628628
]
629629
},
630630
{
@@ -658,7 +658,7 @@
658658
"plotter = mdl.util.PeriodicPlotter(sec=2, xlabel='Iterations', ylabel='Loss', scale='semilogy')\n",
659659
"optimizer = tf.keras.optimizers.SGD(learning_rate=1e-2) # define our optimizer\n",
660660
"\n",
661-
"comet_ml.init(project_name=\"6.s191lab2.1.3\")\n",
661+
"comet_ml.init(project_name=\"6.s191lab2_part1_CNN2\")\n",
662662
"comet_model_3 = comet_ml.Experiment()\n",
663663
"\n",
664664
"if hasattr(tqdm, '_instances'): tqdm._instances.clear() # clear if it exists\n",
@@ -686,6 +686,7 @@
686686
" grads = # TODO\n",
687687
" optimizer.apply_gradients(zip(grads, cnn_model.trainable_variables))\n",
688688
"\n",
689+
"comet_model_3.log_figure(figure=plt)\n",
689690
"comet_model_3.end()\n"
690691
]
691692
},

lab2/Part2_FaceDetection.ipynb

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@
7575
},
7676
"outputs": [],
7777
"source": [
78-
"# Import Comet\n",
79-
"!pip install comet_ml\n",
80-
"import comet_ml\n",
81-
"comet_ml.init(project_name=\"6.s191lab2.2.1\")\n",
82-
"comet_model_1 = comet_ml.Experiment()\n",
83-
"\n",
8478
"# Import Tensorflow 2.0\n",
8579
"%tensorflow_version 2.x\n",
8680
"import tensorflow as tf\n",
@@ -91,10 +85,15 @@
9185
"import numpy as np\n",
9286
"from tqdm import tqdm\n",
9387
"\n",
94-
"\n",
9588
"# Download and import the MIT Introduction to Deep Learning package\n",
9689
"!pip install mitdeeplearning\n",
97-
"import mitdeeplearning as mdl"
90+
"import mitdeeplearning as mdl\n",
91+
"\n",
92+
"# Import Comet\n",
93+
"!pip install comet_ml\n",
94+
"import comet_ml\n",
95+
"comet_ml.init(project_name=\"6.s191lab2_part2_CNN\")\n",
96+
"comet_model_1 = comet_ml.Experiment()"
9897
]
9998
},
10099
{
@@ -185,7 +184,8 @@
185184
"\n",
186185
"plt.subplot(1, 2, 2)\n",
187186
"plt.imshow(not_face_images[idx_not_face])\n",
188-
"plt.title(\"Not Face\"); plt.grid(False)"
187+
"plt.title(\"Not Face\"); plt.grid(False)\n",
188+
"comet_model_1.log_figure(figure=plt)"
189189
]
190190
},
191191
{
@@ -310,6 +310,8 @@
310310
" # Record the loss and plot the evolution of the loss as a function of training\n",
311311
" loss_history.append(loss.numpy().mean())\n",
312312
" plotter.plot(loss_history.get())\n",
313+
"\n",
314+
"comet_model_1.log_figure(figure=plt)\n",
313315
"comet_model_1.end()"
314316
]
315317
},
@@ -764,7 +766,7 @@
764766
"source": [
765767
"### Training the SS-VAE ###\n",
766768
"\n",
767-
"comet_ml.init(project_name=\"6.s191lab2.2.2\")\n",
769+
"comet_ml.init(project_name=\"6.s191lab2_part2_VAE\")\n",
768770
"comet_model_2 = comet_ml.Experiment()\n",
769771
"\n",
770772
"# Hyperparameters\n",
@@ -821,9 +823,7 @@
821823
" \n",
822824
" # plot the progress every 200 steps\n",
823825
" if j % 500 == 0: \n",
824-
" mdl.util.plot_sample(x, y, ss_vae)\n",
825-
" \n",
826-
"comet_model_2.end()"
826+
" mdl.util.plot_sample(x, y, ss_vae)"
827827
]
828828
},
829829
{
@@ -898,7 +898,9 @@
898898
"\n",
899899
"ax[1].imshow(mdl.util.create_grid_of_images(x[ind[-25:]]))\n",
900900
"ax[1].set_title(\"Samples with the highest reconstruction loss \\n\" + \n",
901-
" f\"Average recon loss: {np.mean(vae_loss[ind[-25:]]):.2f}\");"
901+
" f\"Average recon loss: {np.mean(vae_loss[ind[-25:]]):.2f}\");\n",
902+
"\n",
903+
"comet_model_2.log_figure()"
902904
]
903905
},
904906
{
@@ -964,7 +966,9 @@
964966
"# Visualize all of the reconstructions!\n",
965967
"ax[1].imshow(mdl.util.create_grid_of_images(recons, (1, num_steps)))\n",
966968
"ax[1].set_xlabel(\"Latent step\")\n",
967-
"ax[1].set_ylabel(\"Visualization\");\n"
969+
"ax[1].set_ylabel(\"Visualization\");\n",
970+
"\n",
971+
"comet_model_2.log_figure()"
968972
]
969973
},
970974
{
@@ -1013,7 +1017,10 @@
10131017
"# Plot the results\n",
10141018
"plt.plot(np.linspace(np.min(z_mean), np.max(z_mean), num_steps+1), accuracy_per_latent,'-o')\n",
10151019
"plt.xlabel(\"Latent step\")\n",
1016-
"plt.ylabel(\"Relative accuracy\")"
1020+
"plt.ylabel(\"Relative accuracy\")\n",
1021+
"\n",
1022+
"comet_model_2.log_figure()\n",
1023+
"comet_model_2.end()"
10171024
]
10181025
},
10191026
{

0 commit comments

Comments
 (0)