Skip to content

Commit

Permalink
fix copyright (PaddlePaddle#461)
Browse files Browse the repository at this point in the history
* fix  copyright

* fix  copyright 2

* fix  copyright 3
  • Loading branch information
wangna11BD authored Nov 5, 2021
1 parent 3e6fb64 commit bc27b74
Show file tree
Hide file tree
Showing 27 changed files with 658 additions and 460 deletions.
6 changes: 2 additions & 4 deletions ppgan/apps/styleganv2fitting_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ def make_image(tensor):


class StyleGANv2FittingPredictor(StyleGANv2Predictor):
def run(
self,
def run(self,
image,
need_align=False,
start_lr=0.1,
final_lr=0.025,
latent_level=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11], # for ffhq (0~17)
latent_level=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
step=100,
mse_weight=1,
pre_latent=None):
Expand Down
4 changes: 2 additions & 2 deletions ppgan/datasets/animeganv2_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def __init__(self,
"""Initialize this dataset class.
Args:
cfg (dict) -- stores all the experiment flags
dataroot (dict): Directory of dataset.
"""
# self.cfg = cfg
self.root = dataroot
self.style = style

Expand Down
3 changes: 1 addition & 2 deletions ppgan/datasets/firstorder_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def __getitem__(self, idx):
out['driving'] = out['source']
out['source'] = buf
else:
video = np.stack(video_array, axis=0).astype(
np.float32) / 255.0
video = np.stack(video_array, axis=0).astype(np.float32) / 255.0
out['video'] = video.transpose(3, 0, 1, 2)
out['name'] = video_name
return out
Expand Down
16 changes: 3 additions & 13 deletions ppgan/datasets/mpr_dataset.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# code was heavily based on https://github.com/swz30/MPRNet
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/swz30/MPRNet/blob/main/LICENSE.md

import os
import random
Expand Down
24 changes: 15 additions & 9 deletions ppgan/datasets/starganv2_dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# code was heavily based on https://github.com/clovaai/stargan-v2
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/clovaai/stargan-v2#license

import paddle
from .base_dataset import BaseDataset
Expand All @@ -14,8 +17,11 @@


def listdir(dname):
fnames = list(chain(*[list(Path(dname).rglob('*.' + ext))
for ext in ['png', 'jpg', 'jpeg', 'JPG']]))
fnames = list(
chain(*[
list(Path(dname).rglob('*.' + ext))
for ext in ['png', 'jpg', 'jpeg', 'JPG']
]))
return fnames


Expand Down Expand Up @@ -97,7 +103,6 @@ def __len__(self):
return len(self.targets)



@DATASETS.register()
class StarGANv2Dataset(BaseDataset):
"""
Expand All @@ -120,23 +125,24 @@ def __init__(self, dataroot, is_train, preprocess, test_count=0):
else:
files = os.listdir(self.dataroot)
if 'src' in files and 'ref' in files:
self.src_loader = ImageFolder(os.path.join(self.dataroot, 'src'))
self.ref_loader = ImageFolder(os.path.join(self.dataroot, 'ref'))
self.src_loader = ImageFolder(os.path.join(
self.dataroot, 'src'))
self.ref_loader = ImageFolder(os.path.join(
self.dataroot, 'ref'))
else:
self.src_loader = ImageFolder(self.dataroot)
self.ref_loader = ImageFolder(self.dataroot)
self.counts = min(test_count, len(self.src_loader))
self.counts = min(self.counts, len(self.ref_loader))


def _fetch_inputs(self):
try:
x, y = next(self.iter_src)
except (AttributeError, StopIteration):
self.iter_src = iter(self.src_loader)
x, y = next(self.iter_src)
return x, y

def _fetch_refs(self):
try:
x, x2, y = next(self.iter_ref)
Expand Down Expand Up @@ -165,14 +171,14 @@ def __getitem__(self, idx):
'ref_path': x_ref,
'ref_cls': y_ref,
}

if hasattr(self, 'preprocess') and self.preprocess:
datas = self.preprocess(datas)

return datas

def __len__(self):
return self.counts

def prepare_data_infos(self, dataroot):
pass
14 changes: 9 additions & 5 deletions ppgan/models/animeganv2_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

@MODELS.register()
class AnimeGANV2Model(BaseModel):
""" This class implements the AnimeGANV2 model.
"""
def __init__(self,
generator,
discriminator=None,
Expand All @@ -40,8 +42,10 @@ def __init__(self,
tv_weight=1.):
"""Initialize the AnimeGANV2 class.
Parameters:
opt (config dict)-- stores all the experiment flags; needs to be a subclass of Dict
Args:
generator (dict): config of generator.
discriminator (dict): config of discriminator.
gan_criterion (dict): config of gan criterion.
"""
super(AnimeGANV2Model, self).__init__()
self.g_adv_weight = g_adv_weight
Expand All @@ -54,7 +58,7 @@ def __init__(self,
self.nets['netG'] = build_generator(generator)
init_weights(self.nets['netG'])

# define a discriminator; conditional GANs need to take both input and output images; Therefore, #channels for D is input_nc + output_nc
# define a discriminator
if self.is_train:
self.nets['netD'] = build_discriminator(discriminator)
init_weights(self.nets['netD'])
Expand Down Expand Up @@ -87,14 +91,14 @@ def setup_input(self, input):

def forward(self):
"""Run forward pass; called by both functions <optimize_parameters> and <test>."""
self.fake = self.nets['netG'](self.real) # G(A)
self.fake = self.nets['netG'](self.real)

# put items to visual dict
self.visual_items['real'] = self.real
self.visual_items['fake'] = self.fake

def test(self):
self.fake = self.nets['netG'](self.real) # G(A)
self.fake = self.nets['netG'](self.real)

# put items to visual dict
self.visual_items['real'] = self.real
Expand Down
55 changes: 30 additions & 25 deletions ppgan/models/discriminators/dcdiscriminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# code was heavily based on https://github.com/aidotse/Team-Haste
# MIT License
# Copyright (c) 2020 AI Sweden

import paddle
import functools
import numpy as np
Expand All @@ -31,15 +35,14 @@ def __init__(self, input_nc, ndf=64, norm_type='instance'):
"""Construct a DCGAN discriminator
Parameters:
input_nc (int) -- the number of channels in input images
ndf (int) -- the number of filters in the last conv layer
norm_type (str) -- normalization layer type
input_nc (int): the number of channels in input images
ndf (int): the number of filters in the last conv layer
norm_type (str): normalization layer type
"""
super(DCDiscriminator, self).__init__()
norm_layer = build_norm_layer(norm_type)
if type(
norm_layer
) == functools.partial: # no need to use bias as BatchNorm2d has affine parameters
if type(norm_layer) == functools.partial:
# no need to use bias as BatchNorm2d has affine parameters
use_bias = norm_layer.func == nn.BatchNorm2D
else:
use_bias = norm_layer == nn.BatchNorm2D
Expand All @@ -48,29 +51,30 @@ def __init__(self, input_nc, ndf=64, norm_type='instance'):
padw = 1

sequence = [
nn.Conv2D(input_nc,
ndf,
kernel_size=kw,
stride=2,
padding=padw,
bias_attr=use_bias),
nn.LeakyReLU(0.2)
]
nn.Conv2D(input_nc,
ndf,
kernel_size=kw,
stride=2,
padding=padw,
bias_attr=use_bias),
nn.LeakyReLU(0.2)
]

nf_mult = 1
nf_mult_prev = 1
n_downsampling = 4

for n in range(1, n_downsampling): # gradually increase the number of filters
# gradually increase the number of filters
for n in range(1, n_downsampling):
nf_mult_prev = nf_mult
nf_mult = min(2**n, 8)
if norm_type == 'batch':
sequence += [
nn.Conv2D(ndf * nf_mult_prev,
ndf * nf_mult,
kernel_size=kw,
stride=2,
padding=padw),
ndf * nf_mult,
kernel_size=kw,
stride=2,
padding=padw),
BatchNorm2D(ndf * nf_mult),
nn.LeakyReLU(0.2)
]
Expand All @@ -88,13 +92,14 @@ def __init__(self, input_nc, ndf=64, norm_type='instance'):

nf_mult_prev = nf_mult

# output 1 channel prediction map
sequence += [
nn.Conv2D(ndf * nf_mult_prev,
1,
kernel_size=kw,
stride=1,
padding=0)
] # output 1 channel prediction map
nn.Conv2D(ndf * nf_mult_prev,
1,
kernel_size=kw,
stride=1,
padding=0)
]

self.model = nn.Sequential(*sequence)

Expand Down
16 changes: 3 additions & 13 deletions ppgan/models/discriminators/discriminator_animegan.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
# code was heavily based on https://github.com/TachibanaYoshino/AnimeGANv2
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/TachibanaYoshino/AnimeGANv2#license

import paddle.nn as nn
import paddle.nn.functional as F
Expand Down
5 changes: 4 additions & 1 deletion ppgan/models/discriminators/discriminator_starganv2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# code was heavily based on https://github.com/clovaai/stargan-v2
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/clovaai/stargan-v2#license

import paddle.nn as nn
import paddle
Expand All @@ -18,7 +21,7 @@ def __init__(self, img_size=256, num_domains=2, max_conv_dim=512):

repeat_num = int(np.log2(img_size)) - 2
for _ in range(repeat_num):
dim_out = min(dim_in*2, max_conv_dim)
dim_out = min(dim_in * 2, max_conv_dim)
blocks += [ResBlk(dim_in, dim_out, downsample=True)]
dim_in = dim_out

Expand Down
4 changes: 4 additions & 0 deletions ppgan/models/discriminators/discriminator_styleganv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# code was heavily based on https://github.com/rosinality/stylegan2-pytorch
# MIT License
# Copyright (c) 2019 Kim Seonghyeon

import math
import paddle
import paddle.nn as nn
Expand Down
2 changes: 2 additions & 0 deletions ppgan/models/firstorder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.

# code was heavily based on https://github.com/AliaksandrSiarohin/first-order-model
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/AliaksandrSiarohin/first-order-model/blob/master/LICENSE.md

import paddle

Expand Down
Loading

0 comments on commit bc27b74

Please sign in to comment.