Skip to content

first #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PyTorch Workflow

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install torch torchvision
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/sbsa /" | sudo tee /etc/apt/sources.list.d/cuda.list
sudo apt-get update
sudo apt-get -y install cuda

- name: Checkout code
uses: actions/checkout@v2

- name: Run PyTorch code
run: python main.py
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,20 @@
# Update D
optimizerD.step()

# TRAINING THE GENERATOR
# netG.zero_grad()
# target = Variable(torch.ones(real.size()[0])).to(device)
# output = netD(generated)
# TRAINING THE GENERATOR
netG.zero_grad()
target = Variable(torch.ones(real.size()[0])).to(device)
generated = netG(profile)
generated_eyes, generated_nose, generated_cheeks = netG(profile) # Extract the generated components

output = netD(generated)




# G wants to :
# (a) have the synthetic images be accepted by D (= look like frontal images of people)
Expand Down
119 changes: 89 additions & 30 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,114 @@ def weights_init(m):


''' Generator network for 128x128 RGB images '''
class G(nn.Module):
# class G(nn.Module):

# def __init__(self):
# super(G, self).__init__()

# self.main = nn.Sequential(
# # Input HxW = 128x128
# nn.Conv2d(3, 16, 4, 2, 1), # Output HxW = 64x64
# nn.BatchNorm2d(16),
# nn.ReLU(True),
# nn.Conv2d(16, 32, 4, 2, 1), # Output HxW = 32x32
# nn.BatchNorm2d(32),
# nn.ReLU(True),
# nn.Conv2d(32, 64, 4, 2, 1), # Output HxW = 16x16
# nn.BatchNorm2d(64),
# nn.ReLU(True),
# nn.Conv2d(64, 128, 4, 2, 1), # Output HxW = 8x8
# nn.BatchNorm2d(128),
# nn.ReLU(True),
# nn.Conv2d(128, 256, 4, 2, 1), # Output HxW = 4x4
# nn.BatchNorm2d(256),
# nn.ReLU(True),
# nn.Conv2d(256, 512, 4, 2, 1), # Output HxW = 2x2
# nn.MaxPool2d((2,2)),
# # At this point, we arrive at our low D representation vector, which is 512 dimensional.

# nn.ConvTranspose2d(512, 256, 4, 1, 0, bias = False), # Output HxW = 4x4
# nn.BatchNorm2d(256),
# nn.ReLU(True),
# nn.ConvTranspose2d(256, 128, 4, 2, 1, bias = False), # Output HxW = 8x8
# nn.BatchNorm2d(128),
# nn.ReLU(True),
# nn.ConvTranspose2d(128, 64, 4, 2, 1, bias = False), # Output HxW = 16x16
# nn.BatchNorm2d(64),
# nn.ReLU(True),
# nn.ConvTranspose2d(64, 32, 4, 2, 1, bias = False), # Output HxW = 32x32
# nn.BatchNorm2d(32),
# nn.ReLU(True),
# nn.ConvTranspose2d(32, 16, 4, 2, 1, bias = False), # Output HxW = 64x64
# nn.BatchNorm2d(16),
# nn.ReLU(True),
# nn.ConvTranspose2d(16, 3, 4, 2, 1, bias = False), # Output HxW = 128x128
# nn.Tanh()
# )


# def forward(self, input):
# output = self.main(input)
# return output

class G(nn.Module):
def __init__(self):
super(G, self).__init__()

self.main = nn.Sequential(
# Input HxW = 128x128
nn.Conv2d(3, 16, 4, 2, 1), # Output HxW = 64x64
nn.BatchNorm2d(16),
nn.ReLU(True),
nn.Conv2d(16, 32, 4, 2, 1), # Output HxW = 32x32

# Eyes branch
self.eyes = nn.Sequential(
# Add layers specific to generating eyes
nn.Conv2d(3, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.Conv2d(32, 64, 4, 2, 1), # Output HxW = 16x16
nn.Conv2d(32, 64, 4, 2, 1),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.Conv2d(64, 128, 4, 2, 1), # Output HxW = 8x8
nn.BatchNorm2d(128),
nn.ReLU(True),
nn.Conv2d(128, 256, 4, 2, 1), # Output HxW = 4x4
nn.BatchNorm2d(256),
nn.ConvTranspose2d(64, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.Conv2d(256, 512, 4, 2, 1), # Output HxW = 2x2
nn.MaxPool2d((2,2)),
# At this point, we arrive at our low D representation vector, which is 512 dimensional.
nn.ConvTranspose2d(32, 3, 4, 2, 1),
nn.Tanh()
)

nn.ConvTranspose2d(512, 256, 4, 1, 0, bias = False), # Output HxW = 4x4
nn.BatchNorm2d(256),
nn.ReLU(True),
nn.ConvTranspose2d(256, 128, 4, 2, 1, bias = False), # Output HxW = 8x8
nn.BatchNorm2d(128),
# Nose branch
self.nose = nn.Sequential(
# Add layers specific to generating nose
nn.Conv2d(3, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.ConvTranspose2d(128, 64, 4, 2, 1, bias = False), # Output HxW = 16x16
nn.Conv2d(32, 64, 4, 2, 1),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.ConvTranspose2d(64, 32, 4, 2, 1, bias = False), # Output HxW = 32x32
nn.ConvTranspose2d(64, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.ConvTranspose2d(32, 3, 4, 2, 1),
nn.Tanh()
)

# Cheeks branch
self.cheeks = nn.Sequential(
# Add layers specific to generating cheeks
nn.Conv2d(3, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.ConvTranspose2d(32, 16, 4, 2, 1, bias = False), # Output HxW = 64x64
nn.BatchNorm2d(16),
nn.Conv2d(32, 64, 4, 2, 1),
nn.BatchNorm2d(64),
nn.ReLU(True),
nn.ConvTranspose2d(64, 32, 4, 2, 1),
nn.BatchNorm2d(32),
nn.ReLU(True),
nn.ConvTranspose2d(16, 3, 4, 2, 1, bias = False), # Output HxW = 128x128
nn.ConvTranspose2d(32, 3, 4, 2, 1),
nn.Tanh()
)


def forward(self, input):
output = self.main(input)
return output
eyes_output = self.eyes(input)
nose_output = self.nose(input)
cheeks_output = self.cheeks(input)

return eyes_output, nose_output, cheeks_output


''' Discriminator network for 128x128 RGB images '''
Expand Down