|
6 | 6 | "name": "pix2pix(2016).ipynb",
|
7 | 7 | "provenance": [],
|
8 | 8 | "machine_shape": "hm",
|
9 |
| - "authorship_tag": "ABX9TyN2YQrXN7TVuSj3zNIUbCHW", |
| 9 | + "authorship_tag": "ABX9TyMt3J3nGrabI++eewLqG6Ia", |
10 | 10 | "include_colab_link": true
|
11 | 11 | },
|
12 | 12 | "kernelspec": {
|
|
64 | 64 | "\n",
|
65 | 65 | "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
|
66 | 66 | ],
|
67 |
| - "execution_count": 23, |
| 67 | + "execution_count": null, |
68 | 68 | "outputs": []
|
69 | 69 | },
|
70 | 70 | {
|
|
88 | 88 | "source": [
|
89 | 89 | "!git clone https://github.com/mrzhu-cool/pix2pix-pytorch # 깃 클론"
|
90 | 90 | ],
|
91 |
| - "execution_count": 2, |
| 91 | + "execution_count": null, |
92 | 92 | "outputs": [
|
93 | 93 | {
|
94 | 94 | "output_type": "stream",
|
|
110 | 110 | "source": [
|
111 | 111 | "!mkdir 'data' # 폴더 생성"
|
112 | 112 | ],
|
113 |
| - "execution_count": 3, |
| 113 | + "execution_count": null, |
114 | 114 | "outputs": []
|
115 | 115 | },
|
116 | 116 | {
|
|
156 | 156 | " def __len__(self):\n",
|
157 | 157 | " return len(self.img_filenames)"
|
158 | 158 | ],
|
159 |
| - "execution_count": 69, |
| 159 | + "execution_count": null, |
160 | 160 | "outputs": []
|
161 | 161 | },
|
162 | 162 | {
|
|
172 | 172 | " transforms.Resize((256,256))\n",
|
173 | 173 | "])"
|
174 | 174 | ],
|
175 |
| - "execution_count": 70, |
| 175 | + "execution_count": null, |
176 | 176 | "outputs": []
|
177 | 177 | },
|
178 | 178 | {
|
|
185 | 185 | "path2img = '/content/data/facades/train'\n",
|
186 | 186 | "train_ds = FacadeDataset(path2img, transform=transform)"
|
187 | 187 | ],
|
188 |
| - "execution_count": 71, |
| 188 | + "execution_count": null, |
189 | 189 | "outputs": []
|
190 | 190 | },
|
191 | 191 | {
|
|
209 | 209 | "plt.imshow(to_pil_image(0.5*b+0.5))\n",
|
210 | 210 | "plt.axis('off')"
|
211 | 211 | ],
|
212 |
| - "execution_count": 72, |
| 212 | + "execution_count": null, |
213 | 213 | "outputs": [
|
214 | 214 | {
|
215 | 215 | "output_type": "execute_result",
|
|
247 | 247 | "# 데이터 로더 생성하기\n",
|
248 | 248 | "train_dl = DataLoader(train_ds, batch_size=32, shuffle=True)"
|
249 | 249 | ],
|
250 |
| - "execution_count": 73, |
| 250 | + "execution_count": null, |
251 | 251 | "outputs": []
|
252 | 252 | },
|
253 | 253 | {
|
|
296 | 296 | "down_out = model(x)\n",
|
297 | 297 | "print(down_out.shape)"
|
298 | 298 | ],
|
299 |
| - "execution_count": 74, |
| 299 | + "execution_count": null, |
300 | 300 | "outputs": [
|
301 | 301 | {
|
302 | 302 | "output_type": "stream",
|
|
343 | 343 | "out = model(x,down_out)\n",
|
344 | 344 | "print(out.shape)"
|
345 | 345 | ],
|
346 |
| - "execution_count": 75, |
| 346 | + "execution_count": null, |
347 | 347 | "outputs": [
|
348 | 348 | {
|
349 | 349 | "output_type": "stream",
|
|
417 | 417 | "out = model(x)\n",
|
418 | 418 | "print(out.shape)"
|
419 | 419 | ],
|
420 |
| - "execution_count": 76, |
| 420 | + "execution_count": null, |
421 | 421 | "outputs": [
|
422 | 422 | {
|
423 | 423 | "output_type": "stream",
|
|
459 | 459 | "out = model(x)\n",
|
460 | 460 | "print(out.shape)"
|
461 | 461 | ],
|
462 |
| - "execution_count": 77, |
| 462 | + "execution_count": null, |
463 | 463 | "outputs": [
|
464 | 464 | {
|
465 | 465 | "output_type": "stream",
|
|
482 | 482 | "source": [
|
483 | 483 | "# Discriminator은 patch gan을 사용합니다.\n",
|
484 | 484 | "# Patch Gan: 이미지를 16x16의 패치로 분할하여 각 패치가 진짜인지 가짜인지 식별합니다.\n",
|
485 |
| - "# low-frequency에서 정확도가 향상됩니다.\n", |
| 485 | + "# high-frequency에서 정확도가 향상됩니다.\n", |
486 | 486 | "\n",
|
487 | 487 | "class Discriminator(nn.Module):\n",
|
488 | 488 | " def __init__(self, in_channels=3):\n",
|
|
510 | 510 | "out = model(x,x)\n",
|
511 | 511 | "print(out.shape)"
|
512 | 512 | ],
|
513 |
| - "execution_count": 78, |
| 513 | + "execution_count": null, |
514 | 514 | "outputs": [
|
515 | 515 | {
|
516 | 516 | "output_type": "stream",
|
|
530 | 530 | "model_gen = GeneratorUNet().to(device)\n",
|
531 | 531 | "model_dis = Discriminator().to(device)"
|
532 | 532 | ],
|
533 |
| - "execution_count": 79, |
| 533 | + "execution_count": null, |
534 | 534 | "outputs": []
|
535 | 535 | },
|
536 | 536 | {
|
|
550 | 550 | "model_gen.apply(initialize_weights);\n",
|
551 | 551 | "model_dis.apply(initialize_weights);"
|
552 | 552 | ],
|
553 |
| - "execution_count": 80, |
| 553 | + "execution_count": null, |
554 | 554 | "outputs": []
|
555 | 555 | },
|
556 | 556 | {
|
|
587 | 587 | "opt_dis = optim.Adam(model_dis.parameters(),lr=lr,betas=(beta1,beta2))\n",
|
588 | 588 | "opt_gen = optim.Adam(model_gen.parameters(),lr=lr,betas=(beta1,beta2))"
|
589 | 589 | ],
|
590 |
| - "execution_count": 81, |
| 590 | + "execution_count": null, |
591 | 591 | "outputs": []
|
592 | 592 | },
|
593 | 593 | {
|
|
656 | 656 | " if batch_count % 100 == 0:\n",
|
657 | 657 | " print('Epoch: %.0f, G_Loss: %.6f, D_Loss: %.6f, time: %.2f min' %(epoch, g_loss.item(), d_loss.item(), (time.time()-start_time)/60))"
|
658 | 658 | ],
|
659 |
| - "execution_count": 82, |
| 659 | + "execution_count": null, |
660 | 660 | "outputs": [
|
661 | 661 | {
|
662 | 662 | "output_type": "stream",
|
|
700 | 700 | "plt.legend()\n",
|
701 | 701 | "plt.show()"
|
702 | 702 | ],
|
703 |
| - "execution_count": 83, |
| 703 | + "execution_count": null, |
704 | 704 | "outputs": [
|
705 | 705 | {
|
706 | 706 | "output_type": "display_data",
|
|
732 | 732 | "torch.save(model_gen.state_dict(), path2weights_gen)\n",
|
733 | 733 | "torch.save(model_dis.state_dict(), path2weights_dis)"
|
734 | 734 | ],
|
735 |
| - "execution_count": 84, |
| 735 | + "execution_count": null, |
736 | 736 | "outputs": []
|
737 | 737 | },
|
738 | 738 | {
|
|
758 | 758 | "weights = torch.load(path2weights_gen)\n",
|
759 | 759 | "model_gen.load_state_dict(weights)"
|
760 | 760 | ],
|
761 |
| - "execution_count": 85, |
| 761 | + "execution_count": null, |
762 | 762 | "outputs": [
|
763 | 763 | {
|
764 | 764 | "output_type": "execute_result",
|
|
790 | 790 | " real_imgs = b\n",
|
791 | 791 | " break"
|
792 | 792 | ],
|
793 |
| - "execution_count": 86, |
| 793 | + "execution_count": null, |
794 | 794 | "outputs": []
|
795 | 795 | },
|
796 | 796 | {
|
|
815 | 815 | " plt.imshow(to_pil_image(0.5*fake_imgs[ii]+0.5))\n",
|
816 | 816 | " plt.axis('off')\n"
|
817 | 817 | ],
|
818 |
| - "execution_count": 87, |
| 818 | + "execution_count": null, |
819 | 819 | "outputs": [
|
820 | 820 | {
|
821 | 821 | "output_type": "display_data",
|
|
840 | 840 | "source": [
|
841 | 841 | ""
|
842 | 842 | ],
|
843 |
| - "execution_count": 87, |
| 843 | + "execution_count": null, |
844 | 844 | "outputs": []
|
845 | 845 | }
|
846 | 846 | ]
|
|
0 commit comments