|
85 | 85 | "import numpy as np\n",
|
86 | 86 | "from tqdm import tqdm\n",
|
87 | 87 | "\n",
|
88 |
| - "\n", |
89 | 88 | "# Download and import the MIT Introduction to Deep Learning package\n",
|
90 | 89 | "!pip install mitdeeplearning\n",
|
91 |
| - "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()" |
92 | 97 | ]
|
93 | 98 | },
|
94 | 99 | {
|
|
179 | 184 | "\n",
|
180 | 185 | "plt.subplot(1, 2, 2)\n",
|
181 | 186 | "plt.imshow(not_face_images[idx_not_face])\n",
|
182 |
| - "plt.title(\"Not Face\"); plt.grid(False)" |
| 187 | + "plt.title(\"Not Face\"); plt.grid(False)\n", |
| 188 | + "comet_model_1.log_figure(figure=plt)" |
183 | 189 | ]
|
184 | 190 | },
|
185 | 191 | {
|
|
300 | 306 | " x, y = loader.get_batch(batch_size)\n",
|
301 | 307 | " loss = standard_train_step(x, y)\n",
|
302 | 308 | "\n",
|
| 309 | + " comet_model_1.log_metric(\"loss\", loss.numpy().mean(), idx)\n", |
303 | 310 | " # Record the loss and plot the evolution of the loss as a function of training\n",
|
304 | 311 | " loss_history.append(loss.numpy().mean())\n",
|
305 |
| - " plotter.plot(loss_history.get())" |
| 312 | + " plotter.plot(loss_history.get())\n", |
| 313 | + "\n", |
| 314 | + "comet_model_1.log_figure(figure=plt)\n", |
| 315 | + "comet_model_1.end()" |
306 | 316 | ]
|
307 | 317 | },
|
308 | 318 | {
|
|
756 | 766 | "source": [
|
757 | 767 | "### Training the SS-VAE ###\n",
|
758 | 768 | "\n",
|
| 769 | + "comet_ml.init(project_name=\"6.s191lab2_part2_VAE\")\n", |
| 770 | + "comet_model_2 = comet_ml.Experiment()\n", |
| 771 | + "\n", |
759 | 772 | "# Hyperparameters\n",
|
760 | 773 | "batch_size = 32\n",
|
761 | 774 | "learning_rate = 5e-4\n",
|
|
806 | 819 | " (x, y) = loader.get_batch(batch_size)\n",
|
807 | 820 | " # loss optimization\n",
|
808 | 821 | " loss = ss_vae_train_step(x, y)\n",
|
| 822 | + " comet_model_2.log_metric(\"loss\", loss, step=j)\n", |
809 | 823 | " \n",
|
810 | 824 | " # plot the progress every 200 steps\n",
|
811 | 825 | " if j % 500 == 0: \n",
|
|
884 | 898 | "\n",
|
885 | 899 | "ax[1].imshow(mdl.util.create_grid_of_images(x[ind[-25:]]))\n",
|
886 | 900 | "ax[1].set_title(\"Samples with the highest reconstruction loss \\n\" + \n",
|
887 |
| - " 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()" |
888 | 904 | ]
|
889 | 905 | },
|
890 | 906 | {
|
|
950 | 966 | "# Visualize all of the reconstructions!\n",
|
951 | 967 | "ax[1].imshow(mdl.util.create_grid_of_images(recons, (1, num_steps)))\n",
|
952 | 968 | "ax[1].set_xlabel(\"Latent step\")\n",
|
953 |
| - "ax[1].set_ylabel(\"Visualization\");\n" |
| 969 | + "ax[1].set_ylabel(\"Visualization\");\n", |
| 970 | + "\n", |
| 971 | + "comet_model_2.log_figure()" |
954 | 972 | ]
|
955 | 973 | },
|
956 | 974 | {
|
|
999 | 1017 | "# Plot the results\n",
|
1000 | 1018 | "plt.plot(np.linspace(np.min(z_mean), np.max(z_mean), num_steps+1), accuracy_per_latent,'-o')\n",
|
1001 | 1019 | "plt.xlabel(\"Latent step\")\n",
|
1002 |
| - "plt.ylabel(\"Relative accuracy\")" |
| 1020 | + "plt.ylabel(\"Relative accuracy\")\n", |
| 1021 | + "\n", |
| 1022 | + "comet_model_2.log_figure()\n", |
| 1023 | + "comet_model_2.end()" |
1003 | 1024 | ]
|
1004 | 1025 | },
|
1005 | 1026 | {
|
|
0 commit comments