Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleGAN
提交
9020cf3c
P
PaddleGAN
项目概览
PaddlePaddle
/
PaddleGAN
大约 1 年 前同步成功
通知
97
Star
7254
Fork
1210
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleGAN
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9020cf3c
编写于
10月 29, 2020
作者:
Q
qingqing01
提交者:
GitHub
10月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Copyright (#60)
上级
605b34ba
变更
75
隐藏空白更改
内联
并排
Showing
75 changed file
with
859 addition
and
98 deletion
+859
-98
applications/tools/ps_demo.py
applications/tools/ps_demo.py
+1
-1
ppgan/apps/__init__.py
ppgan/apps/__init__.py
+14
-0
ppgan/datasets/__init__.py
ppgan/datasets/__init__.py
+1
-1
ppgan/datasets/base_dataset.py
ppgan/datasets/base_dataset.py
+15
-1
ppgan/datasets/builder.py
ppgan/datasets/builder.py
+23
-11
ppgan/datasets/image_folder.py
ppgan/datasets/image_folder.py
+35
-9
ppgan/datasets/makeup_dataset.py
ppgan/datasets/makeup_dataset.py
+1
-1
ppgan/datasets/paired_dataset.py
ppgan/datasets/paired_dataset.py
+14
-0
ppgan/datasets/single_dataset.py
ppgan/datasets/single_dataset.py
+14
-0
ppgan/datasets/sr_image_dataset.py
ppgan/datasets/sr_image_dataset.py
+19
-3
ppgan/datasets/transforms/__init__.py
ppgan/datasets/transforms/__init__.py
+15
-1
ppgan/datasets/transforms/builder.py
ppgan/datasets/transforms/builder.py
+14
-0
ppgan/datasets/transforms/makeup_transforms.py
ppgan/datasets/transforms/makeup_transforms.py
+1
-1
ppgan/datasets/transforms/transforms.py
ppgan/datasets/transforms/transforms.py
+14
-0
ppgan/datasets/unpaired_dataset.py
ppgan/datasets/unpaired_dataset.py
+14
-0
ppgan/engine/trainer.py
ppgan/engine/trainer.py
+14
-0
ppgan/faceutils/__init__.py
ppgan/faceutils/__init__.py
+1
-1
ppgan/faceutils/dlibutils/__init__.py
ppgan/faceutils/dlibutils/__init__.py
+14
-0
ppgan/faceutils/dlibutils/dlib_utils.py
ppgan/faceutils/dlibutils/dlib_utils.py
+1
-1
ppgan/faceutils/image.py
ppgan/faceutils/image.py
+14
-0
ppgan/faceutils/mask/__init__.py
ppgan/faceutils/mask/__init__.py
+1
-1
ppgan/faceutils/mask/face_parser.py
ppgan/faceutils/mask/face_parser.py
+14
-0
ppgan/faceutils/mask/model.py
ppgan/faceutils/mask/model.py
+1
-1
ppgan/metric/compute_fid.py
ppgan/metric/compute_fid.py
+26
-13
ppgan/metric/inception.py
ppgan/metric/inception.py
+1
-1
ppgan/metric/metric_util.py
ppgan/metric/metric_util.py
+18
-2
ppgan/metric/psnr_ssim.py
ppgan/metric/psnr_ssim.py
+14
-0
ppgan/metric/test_fid_score.py
ppgan/metric/test_fid_score.py
+11
-6
ppgan/models/__init__.py
ppgan/models/__init__.py
+1
-1
ppgan/models/backbones/__init__.py
ppgan/models/backbones/__init__.py
+15
-1
ppgan/models/backbones/resnet_backbone.py
ppgan/models/backbones/resnet_backbone.py
+14
-0
ppgan/models/base_model.py
ppgan/models/base_model.py
+14
-0
ppgan/models/builder.py
ppgan/models/builder.py
+14
-0
ppgan/models/cycle_gan_model.py
ppgan/models/cycle_gan_model.py
+14
-0
ppgan/models/discriminators/__init__.py
ppgan/models/discriminators/__init__.py
+15
-1
ppgan/models/discriminators/builder.py
ppgan/models/discriminators/builder.py
+14
-1
ppgan/models/discriminators/nlayers.py
ppgan/models/discriminators/nlayers.py
+1
-1
ppgan/models/generators/__init__.py
ppgan/models/generators/__init__.py
+1
-1
ppgan/models/generators/builder.py
ppgan/models/generators/builder.py
+14
-1
ppgan/models/generators/deoldify.py
ppgan/models/generators/deoldify.py
+14
-0
ppgan/models/generators/hook.py
ppgan/models/generators/hook.py
+14
-0
ppgan/models/generators/makeup.py
ppgan/models/generators/makeup.py
+1
-1
ppgan/models/generators/occlusion_aware.py
ppgan/models/generators/occlusion_aware.py
+14
-0
ppgan/models/generators/remaster.py
ppgan/models/generators/remaster.py
+14
-0
ppgan/models/generators/resnet.py
ppgan/models/generators/resnet.py
+14
-0
ppgan/models/generators/rrdb_net.py
ppgan/models/generators/rrdb_net.py
+14
-0
ppgan/models/generators/unet.py
ppgan/models/generators/unet.py
+14
-0
ppgan/models/losses.py
ppgan/models/losses.py
+14
-1
ppgan/models/makeup_model.py
ppgan/models/makeup_model.py
+1
-1
ppgan/models/pix2pix_model.py
ppgan/models/pix2pix_model.py
+14
-0
ppgan/models/sr_model.py
ppgan/models/sr_model.py
+14
-0
ppgan/models/srgan_model.py
ppgan/models/srgan_model.py
+14
-0
ppgan/modules/dense_motion.py
ppgan/modules/dense_motion.py
+14
-0
ppgan/modules/first_order.py
ppgan/modules/first_order.py
+14
-0
ppgan/modules/init.py
ppgan/modules/init.py
+18
-3
ppgan/modules/keypoint_detector.py
ppgan/modules/keypoint_detector.py
+14
-0
ppgan/modules/nn.py
ppgan/modules/nn.py
+1
-1
ppgan/modules/norm.py
ppgan/modules/norm.py
+14
-0
ppgan/solver/__init__.py
ppgan/solver/__init__.py
+15
-1
ppgan/solver/lr_scheduler.py
ppgan/solver/lr_scheduler.py
+14
-0
ppgan/solver/optimizer.py
ppgan/solver/optimizer.py
+14
-0
ppgan/utils/animate.py
ppgan/utils/animate.py
+14
-0
ppgan/utils/config.py
ppgan/utils/config.py
+5
-8
ppgan/utils/filesystem.py
ppgan/utils/filesystem.py
+14
-0
ppgan/utils/image_pool.py
ppgan/utils/image_pool.py
+21
-6
ppgan/utils/logger.py
ppgan/utils/logger.py
+14
-0
ppgan/utils/options.py
ppgan/utils/options.py
+1
-1
ppgan/utils/preprocess.py
ppgan/utils/preprocess.py
+1
-1
ppgan/utils/registry.py
ppgan/utils/registry.py
+21
-4
ppgan/utils/setup.py
ppgan/utils/setup.py
+14
-0
ppgan/utils/timer.py
ppgan/utils/timer.py
+1
-1
ppgan/utils/video.py
ppgan/utils/video.py
+16
-1
ppgan/utils/visual.py
ppgan/utils/visual.py
+17
-1
setup.py
setup.py
+3
-4
tools/main.py
tools/main.py
+1
-1
未找到文件。
applications/tools/ps_demo.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/apps/__init__.py
浏览文件 @
9020cf3c
# 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.
from
.dain_predictor
import
DAINPredictor
from
.deepremaster_predictor
import
DeepRemasterPredictor
from
.deoldify_predictor
import
DeOldifyPredictor
...
...
ppgan/datasets/__init__.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/datasets/base_dataset.py
浏览文件 @
9020cf3c
# 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/junyanz/pytorch-CycleGAN-and-pix2pix
import
random
import
numpy
as
np
...
...
@@ -98,5 +112,5 @@ def get_transform(cfg,
transform_list
+=
[
transforms
.
Normalize
(
cfg
.
normalize
.
mean
,
cfg
.
normalize
.
std
)
]
return
transforms
.
Compose
(
transform_list
)
ppgan/datasets/builder.py
浏览文件 @
9020cf3c
# 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.
import
time
import
paddle
import
numbers
...
...
@@ -59,17 +73,15 @@ class DictDataLoader():
place
=
paddle
.
CUDAPlace
(
ParallelEnv
().
dev_id
)
\
if
ParallelEnv
().
nranks
>
1
else
paddle
.
CUDAPlace
(
0
)
sampler
=
DistributedBatchSampler
(
self
.
dataset
,
batch_size
=
batch_size
,
shuffle
=
True
if
is_train
else
False
,
drop_last
=
True
if
is_train
else
False
)
self
.
dataloader
=
paddle
.
io
.
DataLoader
(
self
.
dataset
,
batch_sampler
=
sampler
,
places
=
place
,
num_workers
=
num_workers
)
sampler
=
DistributedBatchSampler
(
self
.
dataset
,
batch_size
=
batch_size
,
shuffle
=
True
if
is_train
else
False
,
drop_last
=
True
if
is_train
else
False
)
self
.
dataloader
=
paddle
.
io
.
DataLoader
(
self
.
dataset
,
batch_sampler
=
sampler
,
places
=
place
,
num_workers
=
num_workers
)
self
.
batch_size
=
batch_size
...
...
ppgan/datasets/image_folder.py
浏览文件 @
9020cf3c
# 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.
"""A modified image folder class
We modify the official PyTorch image folder (https://github.com/pytorch/vision/blob/master/torchvision/datasets/folder.py)
...
...
@@ -10,9 +23,20 @@ import os
import
os.path
IMG_EXTENSIONS
=
[
'.jpg'
,
'.JPG'
,
'.jpeg'
,
'.JPEG'
,
'.png'
,
'.PNG'
,
'.ppm'
,
'.PPM'
,
'.bmp'
,
'.BMP'
,
'.tif'
,
'.TIF'
,
'.tiff'
,
'.TIFF'
,
'.jpg'
,
'.JPG'
,
'.jpeg'
,
'.JPEG'
,
'.png'
,
'.PNG'
,
'.ppm'
,
'.PPM'
,
'.bmp'
,
'.BMP'
,
'.tif'
,
'.TIF'
,
'.tiff'
,
'.TIFF'
,
]
...
...
@@ -29,7 +53,7 @@ def make_dataset(dir, max_dataset_size=float("inf")):
if
is_image_file
(
fname
):
path
=
os
.
path
.
join
(
root
,
fname
)
images
.
append
(
path
)
return
images
[:
min
(
float
(
max_dataset_size
),
len
(
images
))]
...
...
@@ -38,14 +62,16 @@ def default_loader(path):
class
ImageFolder
(
Dataset
):
def
__init__
(
self
,
root
,
transform
=
None
,
return_paths
=
False
,
def
__init__
(
self
,
root
,
transform
=
None
,
return_paths
=
False
,
loader
=
default_loader
):
imgs
=
make_dataset
(
root
)
if
len
(
imgs
)
==
0
:
raise
(
RuntimeError
(
"Found 0 images in: "
+
root
+
"
\n
"
"Supported image extensions are: "
+
","
.
join
(
IMG_EXTENSIONS
)))
raise
(
RuntimeError
(
"Found 0 images in: "
+
root
+
"
\n
"
"Supported image extensions are: "
+
","
.
join
(
IMG_EXTENSIONS
)))
self
.
root
=
root
self
.
imgs
=
imgs
...
...
ppgan/datasets/makeup_dataset.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/datasets/paired_dataset.py
浏览文件 @
9020cf3c
# 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.
import
cv2
import
paddle
import
os.path
...
...
ppgan/datasets/single_dataset.py
浏览文件 @
9020cf3c
# 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.
import
cv2
import
paddle
from
.base_dataset
import
BaseDataset
,
get_transform
...
...
ppgan/datasets/sr_image_dataset.py
浏览文件 @
9020cf3c
# 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.
# import mmcv
import
os
import
cv2
...
...
@@ -33,13 +47,15 @@ def scandir(dir_path, suffix=None, recursive=False):
yield
rel_path
else
:
if
recursive
:
yield
from
_scandir
(
entry
.
path
,
suffix
=
suffix
,
recursive
=
recursive
)
yield
from
_scandir
(
entry
.
path
,
suffix
=
suffix
,
recursive
=
recursive
)
else
:
continue
return
_scandir
(
dir_path
,
suffix
=
suffix
,
recursive
=
recursive
)
def
paired_paths_from_folder
(
folders
,
keys
,
filename_tmpl
):
"""Generate paired paths from folders.
"""
...
...
@@ -70,6 +86,7 @@ def paired_paths_from_folder(folders, keys, filename_tmpl):
(
f
'
{
gt_key
}
_path'
,
gt_path
)]))
return
paths
def
paired_random_crop
(
img_gts
,
img_lqs
,
gt_patch_size
,
scale
,
gt_path
):
"""Paired random crop.
...
...
@@ -180,7 +197,6 @@ def augment(imgs, hflip=True, rotation=True, flows=None):
@
DATASETS
.
register
()
class
SRImageDataset
(
Dataset
):
"""Paired image dataset for image restoration."""
def
__init__
(
self
,
cfg
):
super
(
SRImageDataset
,
self
).
__init__
()
self
.
cfg
=
cfg
...
...
ppgan/datasets/transforms/__init__.py
浏览文件 @
9020cf3c
from
.transforms
import
PairedRandomCrop
,
PairedRandomHorizontalFlip
# 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.
from
.transforms
import
PairedRandomCrop
,
PairedRandomHorizontalFlip
ppgan/datasets/transforms/builder.py
浏览文件 @
9020cf3c
# 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.
import
copy
import
traceback
import
paddle
...
...
ppgan/datasets/transforms/makeup_transforms.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/datasets/transforms/transforms.py
浏览文件 @
9020cf3c
# 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.
import
sys
import
random
import
numbers
...
...
ppgan/datasets/unpaired_dataset.py
浏览文件 @
9020cf3c
# 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.
import
cv2
import
random
import
os.path
...
...
ppgan/engine/trainer.py
浏览文件 @
9020cf3c
# 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.
import
os
import
time
import
copy
...
...
ppgan/faceutils/__init__.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/faceutils/dlibutils/__init__.py
浏览文件 @
9020cf3c
# 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.
from
.dlib_utils
import
detect
,
crop
,
landmarks
,
crop_from_array
ppgan/faceutils/dlibutils/dlib_utils.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/faceutils/image.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
import
cv2
from
io
import
BytesIO
...
...
ppgan/faceutils/mask/__init__.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/faceutils/mask/face_parser.py
浏览文件 @
9020cf3c
# 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.
import
os.path
as
osp
import
numpy
as
np
...
...
ppgan/faceutils/mask/model.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/metric/compute_fid.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
@@ -26,6 +26,7 @@ from paddle.fluid.dygraph.base import to_variable
try
:
from
tqdm
import
tqdm
except
:
def
tqdm
(
x
):
return
x
...
...
@@ -131,7 +132,13 @@ def calculate_fid_given_img(img_fake,
return
fid_value
def
_get_activations
(
files
,
model
,
batch_size
,
dims
,
use_gpu
,
premodel_path
,
style
=
None
):
def
_get_activations
(
files
,
model
,
batch_size
,
dims
,
use_gpu
,
premodel_path
,
style
=
None
):
if
len
(
files
)
%
batch_size
!=
0
:
print
((
'Warning: number of images is not a multiple of the '
'batch size. Some samples are going to be ignored.'
))
...
...
@@ -159,8 +166,7 @@ def _get_activations(files, model, batch_size, dims, use_gpu, premodel_path, sty
img_list
.
append
(
np
.
array
(
im
).
astype
(
'float32'
))
images
=
np
.
array
(
img_list
)
images
=
np
.
array
(
img_list
)
else
:
images
=
np
.
array
(
[
imread
(
str
(
f
)).
astype
(
np
.
float32
)
for
f
in
files
[
start
:
end
]])
...
...
@@ -179,7 +185,7 @@ def _get_activations(files, model, batch_size, dims, use_gpu, premodel_path, sty
std
=
np
.
array
([
0.229
,
0.224
,
0.225
]).
astype
(
'float32'
)
images
[:]
=
(
images
[:]
-
mean
[:,
None
,
None
])
/
std
[:,
None
,
None
]
if
style
==
'stargan'
:
if
style
==
'stargan'
:
pred_arr
[
start
:
end
]
=
inception_infer
(
images
,
premodel_path
)
else
:
with
fluid
.
dygraph
.
guard
():
...
...
@@ -197,10 +203,11 @@ def _get_activations(files, model, batch_size, dims, use_gpu, premodel_path, sty
def
inception_infer
(
x
,
model_path
):
exe
=
fluid
.
Executor
()
[
inference_program
,
feed_target_names
,
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
model_path
,
exe
)
[
inference_program
,
feed_target_names
,
fetch_targets
]
=
fluid
.
io
.
load_inference_model
(
model_path
,
exe
)
results
=
exe
.
run
(
inference_program
,
feed
=
{
feed_target_names
[
0
]:
x
},
fetch_list
=
fetch_targets
)
feed
=
{
feed_target_names
[
0
]:
x
},
fetch_list
=
fetch_targets
)
return
results
[
0
]
...
...
@@ -210,7 +217,7 @@ def _calculate_activation_statistics(files,
batch_size
=
50
,
dims
=
2048
,
use_gpu
=
False
,
style
=
None
):
style
=
None
):
act
=
_get_activations
(
files
,
model
,
batch_size
,
dims
,
use_gpu
,
premodel_path
,
style
)
mu
=
np
.
mean
(
act
,
axis
=
0
)
...
...
@@ -218,8 +225,13 @@ def _calculate_activation_statistics(files,
return
mu
,
sigma
def
_compute_statistics_of_path
(
path
,
model
,
batch_size
,
dims
,
use_gpu
,
premodel_path
,
style
=
None
):
def
_compute_statistics_of_path
(
path
,
model
,
batch_size
,
dims
,
use_gpu
,
premodel_path
,
style
=
None
):
if
path
.
endswith
(
'.npz'
):
f
=
np
.
load
(
path
)
m
,
s
=
f
[
'mu'
][:],
f
[
'sigma'
][:]
...
...
@@ -231,7 +243,8 @@ def _compute_statistics_of_path(path, model, batch_size, dims, use_gpu,
filenames
,
'*.jpg'
)
or
fnmatch
.
filter
(
filenames
,
'*.png'
):
files
.
append
(
os
.
path
.
join
(
root
,
filename
))
m
,
s
=
_calculate_activation_statistics
(
files
,
model
,
premodel_path
,
batch_size
,
dims
,
use_gpu
,
style
)
batch_size
,
dims
,
use_gpu
,
style
)
return
m
,
s
...
...
@@ -241,7 +254,7 @@ def calculate_fid_given_paths(paths,
use_gpu
,
dims
,
model
=
None
,
style
=
None
):
style
=
None
):
assert
os
.
path
.
exists
(
premodel_path
),
'pretrain_model path {} is not exists! Please download it first'
.
format
(
...
...
ppgan/metric/inception.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/metric/metric_util.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
...
...
@@ -29,6 +43,7 @@ def reorder_image(img, input_order='HWC'):
img
=
img
.
transpose
(
1
,
2
,
0
)
return
img
def
bgr2ycbcr
(
img
,
y_only
=
False
):
"""Convert a BGR image to YCbCr image.
...
...
@@ -52,16 +67,17 @@ def bgr2ycbcr(img, y_only=False):
and range as input image.
"""
img_type
=
img
.
dtype
img
=
_convert_input_type_range
(
img
)
#
img = _convert_input_type_range(img)
if
y_only
:
out_img
=
np
.
dot
(
img
,
[
24.966
,
128.553
,
65.481
])
+
16.0
else
:
out_img
=
np
.
matmul
(
img
,
[[
24.966
,
112.0
,
-
18.214
],
[
128.553
,
-
74.203
,
-
93.786
],
[
65.481
,
-
37.797
,
112.0
]])
+
[
16
,
128
,
128
]
out_img
=
_convert_output_type_range
(
out_img
,
img_type
)
#
out_img = _convert_output_type_range(out_img, img_type)
return
out_img
def
to_y_channel
(
img
):
"""Change to Y channel of YCbCr.
...
...
ppgan/metric/psnr_ssim.py
浏览文件 @
9020cf3c
# 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.
import
cv2
import
numpy
as
np
...
...
ppgan/metric/test_fid_score.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
@@ -38,9 +38,10 @@ def parse_args():
type
=
int
,
default
=
1
,
help
=
'sample number in a batch for inference.'
)
parser
.
add_argument
(
'--style'
,
type
=
str
,
help
=
'calculation style: stargan or default (gan-compression style)'
)
parser
.
add_argument
(
'--style'
,
type
=
str
,
help
=
'calculation style: stargan or default (gan-compression style)'
)
args
=
parser
.
parse_args
()
return
args
...
...
@@ -53,8 +54,12 @@ def main():
inference_model_path
=
args
.
inference_model
batch_size
=
args
.
batch_size
fid_value
=
calculate_fid_given_paths
(
paths
,
inference_model_path
,
batch_size
,
args
.
use_gpu
,
2048
,
style
=
args
.
style
)
fid_value
=
calculate_fid_given_paths
(
paths
,
inference_model_path
,
batch_size
,
args
.
use_gpu
,
2048
,
style
=
args
.
style
)
print
(
'FID: '
,
fid_value
)
...
...
ppgan/models/__init__.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/models/backbones/__init__.py
浏览文件 @
9020cf3c
from
.resnet_backbone
import
resnet18
,
resnet34
,
resnet50
,
resnet101
,
resnet152
\ No newline at end of file
# 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.
from
.resnet_backbone
import
resnet18
,
resnet34
,
resnet50
,
resnet101
,
resnet152
ppgan/models/backbones/resnet_backbone.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/models/base_model.py
浏览文件 @
9020cf3c
# 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/junyanz/pytorch-CycleGAN-and-pix2pix
import
os
import
paddle
...
...
ppgan/models/builder.py
浏览文件 @
9020cf3c
# 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.
import
paddle
from
..utils.registry
import
Registry
...
...
ppgan/models/cycle_gan_model.py
浏览文件 @
9020cf3c
# 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.
import
paddle
from
.base_model
import
BaseModel
...
...
ppgan/models/discriminators/__init__.py
浏览文件 @
9020cf3c
from
.nlayers
import
NLayerDiscriminator
\ No newline at end of file
# 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.
from
.nlayers
import
NLayerDiscriminator
ppgan/models/discriminators/builder.py
浏览文件 @
9020cf3c
# 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.
import
copy
from
...utils.registry
import
Registry
DISCRIMINATORS
=
Registry
(
"DISCRIMINATOR"
)
...
...
ppgan/models/discriminators/nlayers.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/models/generators/__init__.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/models/generators/builder.py
浏览文件 @
9020cf3c
# 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.
import
copy
from
...utils.registry
import
Registry
GENERATORS
=
Registry
(
"GENERATOR"
)
...
...
ppgan/models/generators/deoldify.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/models/generators/hook.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
import
paddle
...
...
ppgan/models/generators/makeup.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/models/generators/occlusion_aware.py
浏览文件 @
9020cf3c
# 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.
import
paddle
from
paddle
import
nn
import
paddle.nn.functional
as
F
...
...
ppgan/models/generators/remaster.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
...
...
ppgan/models/generators/resnet.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
import
functools
...
...
ppgan/models/generators/rrdb_net.py
浏览文件 @
9020cf3c
# 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.
import
functools
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/models/generators/unet.py
浏览文件 @
9020cf3c
# 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.
import
functools
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/models/losses.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
import
paddle
...
...
@@ -10,7 +24,6 @@ class GANLoss(nn.Layer):
The GANLoss class abstracts away the need to create the target label tensor
that has the same size as the input.
"""
def
__init__
(
self
,
gan_mode
,
target_real_label
=
1.0
,
target_fake_label
=
0.0
):
""" Initialize the GANLoss class.
...
...
ppgan/models/makeup_model.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/models/pix2pix_model.py
浏览文件 @
9020cf3c
# 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.
import
paddle
from
.base_model
import
BaseModel
...
...
ppgan/models/sr_model.py
浏览文件 @
9020cf3c
# 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.
from
collections
import
OrderedDict
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/models/srgan_model.py
浏览文件 @
9020cf3c
# 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.
from
collections
import
OrderedDict
import
paddle
import
paddle.nn
as
nn
...
...
ppgan/modules/dense_motion.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
...
...
ppgan/modules/first_order.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
...
...
ppgan/modules/init.py
浏览文件 @
9020cf3c
# 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.
import
math
import
numpy
as
np
...
...
@@ -256,8 +270,10 @@ def kaiming_init(layer,
distribution
=
'normal'
):
assert
distribution
in
[
'uniform'
,
'normal'
]
if
distribution
==
'uniform'
:
kaiming_uniform_
(
layer
.
weight
,
a
=
a
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
kaiming_uniform_
(
layer
.
weight
,
a
=
a
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
else
:
kaiming_normal_
(
layer
.
weight
,
a
=
a
,
mode
=
mode
,
nonlinearity
=
nonlinearity
)
if
hasattr
(
layer
,
'bias'
)
and
layer
.
bias
is
not
None
:
...
...
@@ -273,7 +289,6 @@ def init_weights(net, init_type='normal', init_gain=0.02):
We use 'normal' in the original pix2pix and CycleGAN paper. But xavier and kaiming might
work better for some applications. Feel free to try yourself.
"""
def
init_func
(
m
):
# define the initialization function
classname
=
m
.
__class__
.
__name__
if
hasattr
(
m
,
'weight'
)
and
(
classname
.
find
(
'Conv'
)
!=
-
1
...
...
ppgan/modules/keypoint_detector.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
...
...
ppgan/modules/nn.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/modules/norm.py
浏览文件 @
9020cf3c
# 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.
import
paddle
import
functools
import
paddle.nn
as
nn
...
...
ppgan/solver/__init__.py
浏览文件 @
9020cf3c
from
.optimizer
import
build_optimizer
\ No newline at end of file
# 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.
from
.optimizer
import
build_optimizer
ppgan/solver/lr_scheduler.py
浏览文件 @
9020cf3c
# 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.
import
paddle
...
...
ppgan/solver/optimizer.py
浏览文件 @
9020cf3c
# 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.
import
copy
import
paddle
...
...
ppgan/utils/animate.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
from
scipy.spatial
import
ConvexHull
...
...
ppgan/utils/config.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
@@ -14,7 +14,6 @@
import
os
import
yaml
__all__
=
[
'get_config'
]
...
...
@@ -65,7 +64,6 @@ def override(dl, ks, v):
ks(list): list of keys
v(str): value to be replaced
"""
def
str2num
(
v
):
try
:
return
eval
(
v
)
...
...
@@ -104,8 +102,8 @@ def override_config(config, options=None):
"""
if
options
is
not
None
:
for
opt
in
options
:
assert
isinstance
(
opt
,
str
),
(
"option({}) should be a str"
.
format
(
opt
))
assert
isinstance
(
opt
,
str
),
(
"option({}) should be a str"
.
format
(
opt
))
assert
"="
in
opt
,
(
"option({}) should contain a ="
"to distinguish between key and value"
.
format
(
opt
))
...
...
@@ -122,9 +120,8 @@ def get_config(fname, overrides=None, show=True):
"""
Read config from file
"""
assert
os
.
path
.
exists
(
fname
),
(
'config file({}) is not exist'
.
format
(
fname
))
assert
os
.
path
.
exists
(
fname
),
(
'config file({}) is not exist'
.
format
(
fname
))
config
=
parse_config
(
fname
)
override_config
(
config
,
overrides
)
return
config
\ No newline at end of file
return
config
ppgan/utils/filesystem.py
浏览文件 @
9020cf3c
# 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.
import
os
import
six
import
pickle
...
...
ppgan/utils/image_pool.py
浏览文件 @
9020cf3c
# 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.
import
random
import
paddle
...
...
@@ -8,7 +22,6 @@ class ImagePool():
This buffer enables us to update discriminators using a history of generated images
rather than the ones produced by the latest generators.
"""
def
__init__
(
self
,
pool_size
):
"""Initialize the ImagePool class
...
...
@@ -37,20 +50,22 @@ class ImagePool():
return_images
=
[]
for
image
in
images
:
image
=
paddle
.
unsqueeze
(
image
,
0
)
if
self
.
num_imgs
<
self
.
pool_size
:
# if the buffer is not full; keep inserting current images to the buffer
if
self
.
num_imgs
<
self
.
pool_size
:
# if the buffer is not full; keep inserting current images to the buffer
self
.
num_imgs
=
self
.
num_imgs
+
1
self
.
images
.
append
(
image
)
return_images
.
append
(
image
)
else
:
p
=
random
.
uniform
(
0
,
1
)
if
p
>
0.5
:
# by 50% chance, the buffer will return a previously stored image, and insert the current image into the buffer
random_id
=
random
.
randint
(
0
,
self
.
pool_size
-
1
)
# randint is inclusive
random_id
=
random
.
randint
(
0
,
self
.
pool_size
-
1
)
# randint is inclusive
# FIXME: clone
# tmp = (self.images[random_id]).detach() #.clone()
tmp
=
self
.
images
[
random_id
]
#.clone()
tmp
=
self
.
images
[
random_id
]
#.clone()
self
.
images
[
random_id
]
=
image
return_images
.
append
(
tmp
)
else
:
# by another 50% chance, the buffer will return the current image
else
:
# by another 50% chance, the buffer will return the current image
return_images
.
append
(
image
)
return_images
=
paddle
.
concat
(
return_images
,
0
)
# collect all the images and return
return_images
=
paddle
.
concat
(
return_images
,
0
)
# collect all the images and return
return
return_images
ppgan/utils/logger.py
浏览文件 @
9020cf3c
# 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.
import
logging
import
os
import
sys
...
...
ppgan/utils/options.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/utils/preprocess.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/utils/registry.py
浏览文件 @
9020cf3c
# 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.
class
Registry
(
object
):
"""
The registry that provides name -> object mapping, to support third-party users' custom modules.
...
...
@@ -13,7 +28,6 @@ class Registry(object):
.. code-block:: python
BACKBONE_REGISTRY.register(MyBackbone)
"""
def
__init__
(
self
,
name
):
"""
Args:
...
...
@@ -26,7 +40,8 @@ class Registry(object):
def
_do_register
(
self
,
name
,
obj
):
assert
(
name
not
in
self
.
_obj_map
),
"An object named '{}' was already registered in '{}' registry!"
.
format
(
name
,
self
.
_name
)
),
"An object named '{}' was already registered in '{}' registry!"
.
format
(
name
,
self
.
_name
)
self
.
_obj_map
[
name
]
=
obj
def
register
(
self
,
obj
=
None
,
name
=
None
):
...
...
@@ -52,6 +67,8 @@ class Registry(object):
def
get
(
self
,
name
):
ret
=
self
.
_obj_map
.
get
(
name
)
if
ret
is
None
:
raise
KeyError
(
"No object named '{}' found in '{}' registry!"
.
format
(
name
,
self
.
_name
))
raise
KeyError
(
"No object named '{}' found in '{}' registry!"
.
format
(
name
,
self
.
_name
))
return
ret
\ No newline at end of file
return
ret
ppgan/utils/setup.py
浏览文件 @
9020cf3c
# 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.
import
os
import
time
import
paddle
...
...
ppgan/utils/timer.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
ppgan/utils/video.py
浏览文件 @
9020cf3c
# 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.
import
os
import
sys
def
video2frames
(
video_path
,
outpath
,
**
kargs
):
def
_dict2str
(
kargs
):
cmd_str
=
''
...
...
@@ -41,4 +56,4 @@ def frames2video(frame_path, video_path, r):
if
os
.
system
(
cmd
)
!=
0
:
raise
RuntimeError
(
'ffmpeg process video: {} error'
.
format
(
video_path
))
sys
.
stdout
.
flush
()
\ No newline at end of file
sys
.
stdout
.
flush
()
ppgan/utils/visual.py
浏览文件 @
9020cf3c
# 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.
import
numpy
as
np
from
PIL
import
Image
...
...
@@ -17,7 +31,9 @@ def tensor2img(input_image, min_max=(-1., 1.), imtype=np.uint8):
image_numpy
=
np
.
tile
(
image_numpy
,
(
3
,
1
,
1
))
image_numpy
=
image_numpy
.
clip
(
min_max
[
0
],
min_max
[
1
])
image_numpy
=
(
image_numpy
-
min_max
[
0
])
/
(
min_max
[
1
]
-
min_max
[
0
])
image_numpy
=
(
np
.
transpose
(
image_numpy
,
(
1
,
2
,
0
)))
*
255.0
# post-processing: tranpose and scaling
image_numpy
=
(
np
.
transpose
(
image_numpy
,
(
1
,
2
,
0
)))
*
255.0
# post-processing: tranpose and scaling
else
:
# if it is a numpy array, do nothing
image_numpy
=
input_image
return
image_numpy
.
astype
(
imtype
)
...
...
setup.py
浏览文件 @
9020cf3c
...
...
@@ -36,9 +36,7 @@ setup(
description
=
'Awesome GAN toolkits based on PaddlePaddle'
,
url
=
'https://github.com/PaddlePaddle/PaddleGAN'
,
download_url
=
'https://github.com/PaddlePaddle/PaddleGAN.git'
,
keywords
=
[
'gan paddlegan'
],
keywords
=
[
'gan paddlegan'
],
classifiers
=
[
'Intended Audience :: Developers'
,
'Operating System :: OS Independent'
,
'Natural Language :: Chinese (Simplified)'
,
...
...
@@ -46,4 +44,5 @@ setup(
'Programming Language :: Python :: 3.5'
,
'Programming Language :: Python :: 3.6'
,
'Programming Language :: Python :: 3.7'
,
'Topic :: Utilities'
],
)
\ No newline at end of file
],
)
tools/main.py
浏览文件 @
9020cf3c
#
c
opyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
C
opyright (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.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录