Skip to content

Commit f1cac03

Browse files
author
kevin1kevin1k
committed
update
1 parent aa97707 commit f1cac03

6 files changed

+888
-12
lines changed

README.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
# FaderNet : Implementation & Study
2-
Alex Liu & Kevin Li, from NTU CSIE
1+
# FaderNet: Implementation & Study
2+
Alex Liu & Kevin Li, NTU CSIE
33

44
---
55
## Desciprtion
66

7-
This is our final project repository of the course ADLxMLDS 2017, Fall.
7+
This is our final project repository of the course ADLxMLDS, 2017 Fall.
88

99
![](fig/fig_2.jpg)
1010

11-
In this project, we implement [FaderNet](https://arxiv.org/pdf/1706.00409.pdf) (NIPS 2017) and do capacity/reproducbility/ablation study. Our results can be find in the [poster](fig/post.pdf).
11+
In this project, we implement [FaderNet](https://arxiv.org/pdf/1706.00409.pdf) (NIPS 2017) and do capacity/reproducbility/ablation study. Our results can be found in the [poster](fig/poster.pdf).
1212

13-
We've noticed that FaceBook had released [the offical github for FaderNet](https://github.com/facebookresearch/FaderNetworks). Since we've started the project slightly earlier than it's release, **ONLY in the part of testing FaderNet on unseen data (out of CelebA) had we used the model & modified the testing code FaceBook released. For all the remaining parts including training & experiments, we're using our own production.**
13+
We've noticed that Facebook had released [the offical github for FaderNet](https://github.com/facebookresearch/FaderNetworks). Since we've started the project slightly earlier than it's release, **ONLY in the part of testing FaderNet on unseen data (out of CelebA) had we used the model & modified the testing code FaceBook released. For all the remaining parts including training & experiments, we're using our own implementation.**
1414

1515

16-
The paper also specified their strategy on model selection, which we are not capable to reproduce due to resource limitaion. With our own model, we obtain a slightly worse result comparing to the paper due to the limitation of computing power and time we have.
16+
The paper also specified their strategy on model selection, which we are not capable to reproduce due to resource limitaion. With our own model, we obtain a slightly worse result than the paper due to the limitation of computing power and time we have.
1717

1818
## Dependency & Requirement
1919

@@ -27,7 +27,6 @@ Please make sure each of them is installed with the correct version
2727
- pandas (0.20.3)
2828
- skimage (0.13.1)
2929
- matplotlib (2.1.1)
30-
- Makefile
3130

3231
### Hardware Requirement
3332

@@ -44,7 +43,7 @@ We're running our experiments with following hardware setting
4443

4544
FaderNet is trained on [CelebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html), which is a large scale human face dataset. If you'd like to train the network yourself, please download CelebA and preprocess it into 256x256 images by running
4645

47-
TODO
46+
python3 train_celeba.py
4847

4948
The training process tooks about 1 million steps (5~7 days) to generate result comparable to original paper.
5049

@@ -59,10 +58,14 @@ To generate [fig2](fig/fig_2.jpg) in the poster (Reproducibility Study in Experi
5958

6059
The result will be slightly better than the one in the poster since it's now using the model 100000 steps after the one we've used in poster.
6160

62-
To generate [fig3]() & [fig4]() in the poster (Ablation Study in Experiments), run
61+
To generate fig3 & fig4 in the poster (Ablation Study in Experiments), run
6362

64-
make aga's code
63+
python3 train_celeba_aga_AttrFirstLayer.py
6564

66-
aga's comments
65+
and
6766

67+
python3 train_celeba_aga_NoDiscriminator.py
6868

69+
Note that to run the 3 training codes such as train_celeba.py, please download CelebA and put them in the places you want.
70+
Then you need to run python3 src/reshape.py
71+
You then need to change the 3 paths in these training codes.

src/fadernet_aga_AttrFirstLayer.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import torch
2+
import torch.nn as nn
3+
from torch.autograd import Variable
4+
5+
def C_BN_ACT(c_in, c_out, activation, transpose=False, dropout=None, bn=True):
6+
layers = []
7+
if transpose:
8+
layers.append(nn.ConvTranspose2d(c_in, c_out, kernel_size=4, stride=2, padding=1, bias=False))
9+
else:
10+
layers.append( nn.Conv2d(c_in, c_out, kernel_size=4, stride=2, padding=1))
11+
if dropout:
12+
layers.append(nn.Dropout2d(dropout))
13+
if bn:
14+
layers.append(nn.BatchNorm2d(c_out))
15+
layers.append(activation)
16+
return nn.Sequential(*layers)
17+
18+
class Encoder(nn.Module):
19+
'''
20+
Input: (batch_size, num_channels, H, W)
21+
Output: (batch_size, 512, H / 2**7, W / 2**7)
22+
'''
23+
def __init__(self,k_list):
24+
super(Encoder, self).__init__()
25+
activation = nn.LeakyReLU(0.2)
26+
layers = []
27+
for i in range(1, len(k_list)):
28+
c_in, c_out = k_list[i - 1], k_list[i]
29+
bn = False if i == len(k_list) - 1 else True
30+
layers.append(C_BN_ACT(c_in, c_out, activation, bn=bn))
31+
self.convs = nn.Sequential(*layers)
32+
33+
def forward(self, x):
34+
Ex = self.convs(x)
35+
return Ex
36+
37+
class Decoder(nn.Module):
38+
'''
39+
Input: (batch_size, 512, H, W), (batch_size, attr_dim)
40+
Output: (batch_size, 3, H * 2**7, W * 2**7)
41+
'''
42+
def __init__(self, k_list, attr_dim, image_size=256, num_channels=3):
43+
super(Decoder, self).__init__()
44+
activation = nn.ReLU()
45+
46+
self.image_size = image_size
47+
if self.image_size == 256:
48+
self.deconv1 = C_BN_ACT(k_list[7] + attr_dim, k_list[6], activation, transpose=True)
49+
self.deconv2 = C_BN_ACT(k_list[6], k_list[5], activation, transpose=True)
50+
self.deconv3 = C_BN_ACT(k_list[5], k_list[4], activation, transpose=True)
51+
self.deconv4 = C_BN_ACT(k_list[4], k_list[3], activation, transpose=True)
52+
self.deconv5 = C_BN_ACT(k_list[3], k_list[2], activation, transpose=True)
53+
self.deconv6 = C_BN_ACT(k_list[2], k_list[1], activation, transpose=True)
54+
self.deconv7 = C_BN_ACT(k_list[1], k_list[0], nn.Tanh(), transpose=True, bn=False)
55+
56+
def repeat_concat(self, Ex, attrs):
57+
H, W = Ex.size()[2], Ex.size()[3]
58+
attrs_ = attrs.repeat(H, W, 1, 1).permute(2, 3, 0, 1)
59+
Ex_ = torch.cat([Ex, attrs_], dim=1)
60+
return Ex_
61+
62+
def forward(self, Ex, attrs):
63+
if self.image_size == 256:
64+
Ex = self.deconv1(self.repeat_concat(Ex, attrs))
65+
Ex = self.deconv2(Ex)
66+
Ex = self.deconv3(Ex)
67+
Ex = self.deconv4(Ex)
68+
Ex = self.deconv5(Ex)
69+
Ex = self.deconv6(Ex)
70+
Ex = self.deconv7(Ex)
71+
return Ex
72+
73+
74+
class Discriminator(nn.Module):
75+
'''
76+
Input: (batch_size, 512, H / 2**7, W / 2**7)
77+
Output: (batch_size, num_attrs)
78+
'''
79+
def __init__(self, num_attrs, image_size=256):
80+
super(Discriminator, self).__init__()
81+
self.image_size = image_size
82+
if image_size == 256:
83+
self.conv = C_BN_ACT(512, 512, nn.LeakyReLU(0.2)) # ReLU? Dropout?
84+
self.fc1 = nn.Linear(512, 512)
85+
self.dp1 = nn.Dropout(0.3)
86+
self.fc2 = nn.Linear(512, num_attrs)
87+
self.dp2 = nn.Dropout(0.3)
88+
89+
def forward(self, Ex):
90+
if self.image_size == 256:
91+
Ex = self.conv(Ex)
92+
p = Ex.view(Ex.size()[0], Ex.size()[1])
93+
p = self.dp1(self.fc1(p))
94+
p = self.dp2(self.fc2(p))
95+
return p

test_attr.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import torch
33
import pandas as pd
44
import numpy as np
5-
from private_test.util import load_images
65
from torch.autograd import Variable
76
from torch.utils.data import DataLoader
87
from src.celeba_dataset import CelebA

0 commit comments

Comments
 (0)