From c1ba69bc946652e57e4dc5f7e6a8aac96db5c1b9 Mon Sep 17 00:00:00 2001 From: TRX_599 <45081961+duncanodhis@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:27:31 +0300 Subject: [PATCH 1/3] Create main.yml --- .github/workflows/main.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..4a90ced --- /dev/null +++ b/.github/workflows/main.yml @@ -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 From c26b2f8ceffe55c4db1111d6b6a7cf7921c9d2ab Mon Sep 17 00:00:00 2001 From: TRX_599 <45081961+duncanodhis@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:28:20 +0300 Subject: [PATCH 2/3] Update main.py --- main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.py b/main.py index fed7bc6..ac0cdae 100644 --- a/main.py +++ b/main.py @@ -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) From dce6cca139456240d2d4ed623dc00646b83e156c Mon Sep 17 00:00:00 2001 From: TRX_599 <45081961+duncanodhis@users.noreply.github.com> Date: Sat, 15 Jul 2023 12:29:02 +0300 Subject: [PATCH 3/3] Update network.py --- network.py | 119 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 30 deletions(-) diff --git a/network.py b/network.py index 64d0cd7..5aaf2cc 100644 --- a/network.py +++ b/network.py @@ -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 '''