Skip to content

Commit 20a2692

Browse files
Татьяна ГайнцеваТатьяна Гайнцева
authored andcommitted
fixed bugs hw3-2 base
1 parent 7c13eca commit 20a2692

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

homework03/homework03_part2_autoencoders_basic.ipynb

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@
276276
" model.to(device)\n",
277277
" gd = optim.Adamax(model.parameters(), lr=0.002)\n",
278278
" dataloader = DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=True)\n",
279-
" losses = []\n",
279+
" \n",
280280
" for epoch in range(num_epoch):\n",
281+
" losses = []\n",
282+
" \n",
281283
" for i, (batch) in enumerate(dataloader):\n",
282284
" gd.zero_grad()\n",
283285
" loss = model.batch_loss(batch.cuda())\n",
@@ -613,7 +615,6 @@
613615
},
614616
"outputs": [],
615617
"source": [
616-
"\n",
617618
"theoretical_std = (X[:100].std()**2 + 0.5**2)**.5\n",
618619
"our_std = apply_gaussian_noise(X[:100],sigma=0.5).std()\n",
619620
"assert abs(theoretical_std - our_std) < 0.01, \"Standard deviation does not match it's required value. Make sure you use sigma as std.\"\n",
@@ -655,35 +656,15 @@
655656
"outputs": [],
656657
"source": [
657658
"def train_noise(model, dataset, num_epoch=50):\n",
658-
" #<Your code: define train function for denoising autoencoder as train function above>"
659-
]
660-
},
661-
{
662-
"cell_type": "code",
663-
"execution_count": null,
664-
"metadata": {
665-
"colab": {},
666-
"colab_type": "code",
667-
"id": "MKQK4HJL_eX2"
668-
},
669-
"outputs": [],
670-
"source": [
671-
"X_train_noise = apply_gaussian_noise(X_train)\n",
672-
"X_test_noise = apply_gaussian_noise(X_test)"
659+
" #<Your code: define train function for denoising autoencoder as train function above>\n",
660+
" #<Think carefully, what should be ground-truth image for computing loss function>"
673661
]
674662
},
675663
{
676-
"cell_type": "code",
677-
"execution_count": null,
678-
"metadata": {
679-
"colab": {},
680-
"colab_type": "code",
681-
"id": "8ClYTlpa_eX4"
682-
},
683-
"outputs": [],
664+
"cell_type": "markdown",
665+
"metadata": {},
684666
"source": [
685-
"X_train_tensor_n = torch.from_numpy(X_train_noise).type(torch.DoubleTensor)\n",
686-
"X_test_tensor_n = torch.Tensor(X_test_noise).type(torch.DoubleTensor)"
667+
"__Note:__ You may change the way the training with noise is done, if you want. For example, you may change Dataloader or batch_loss function in model and leave train function unchanged."
687668
]
688669
},
689670
{
@@ -701,7 +682,7 @@
701682
"outputs": [],
702683
"source": [
703684
"aenc = pca_autoencoder()\n",
704-
"train(aenc, X_train_tensor_n, 50)"
685+
"train_noise(aenc, X_train_tensor, 50)"
705686
]
706687
},
707688
{
@@ -723,7 +704,7 @@
723704
"id": "HVj0NPXV3liL"
724705
},
725706
"source": [
726-
"** Let's evaluate!!! **"
707+
"**Let's evaluate!!!**"
727708
]
728709
},
729710
{
@@ -842,7 +823,7 @@
842823
"def get_similar(image, n_neighbors=5):\n",
843824
" assert len(image.shape)==3,\"image must be [batch,height,width,3]\"\n",
844825
"\n",
845-
" code = aenc.enc(image.cuda(device)).detach().cpu().numpy()\n",
826+
" code = #<Your code: encode image into latent code>\n",
846827
" \n",
847828
" (distances,),(idx,) = #<Your code: using lshf.kneighbors find nearest neighbors>\n",
848829
" \n",
@@ -1023,7 +1004,7 @@
10231004
"name": "python",
10241005
"nbconvert_exporter": "python",
10251006
"pygments_lexer": "ipython3",
1026-
"version": "3.6.2"
1007+
"version": "3.6.9"
10271008
}
10281009
},
10291010
"nbformat": 4,

0 commit comments

Comments
 (0)