Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleGAN
提交
2328f9fb
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看板
未验证
提交
2328f9fb
编写于
11月 04, 2021
作者:
L
LielinJiang
提交者:
GitHub
11月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish code (#457)
上级
7f628db5
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
72 addition
and
91 deletion
+72
-91
ppgan/datasets/wav2lip_dataset.py
ppgan/datasets/wav2lip_dataset.py
+3
-13
ppgan/models/criterions/perceptual_loss.py
ppgan/models/criterions/perceptual_loss.py
+1
-0
ppgan/models/generators/basicvsr.py
ppgan/models/generators/basicvsr.py
+1
-13
ppgan/models/generators/deoldify.py
ppgan/models/generators/deoldify.py
+2
-13
ppgan/models/ugatit_model.py
ppgan/models/ugatit_model.py
+12
-2
ppgan/utils/animate.py
ppgan/utils/animate.py
+2
-0
ppgan/utils/audio.py
ppgan/utils/audio.py
+4
-0
ppgan/utils/audio_config.py
ppgan/utils/audio_config.py
+23
-23
ppgan/utils/config.py
ppgan/utils/config.py
+0
-1
ppgan/utils/image_pool.py
ppgan/utils/image_pool.py
+21
-24
ppgan/utils/logger.py
ppgan/utils/logger.py
+1
-2
ppgan/utils/registry.py
ppgan/utils/registry.py
+2
-0
未找到文件。
ppgan/datasets/wav2lip_dataset.py
浏览文件 @
2328f9fb
# 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/Rudrabha/Wav2Lip
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/Rudrabha/Wav2Lip#license-and-citation
import
cv2
import
random
...
...
ppgan/models/criterions/perceptual_loss.py
浏览文件 @
2328f9fb
# Copyright (c) MMEditing Authors.
import
paddle
import
paddle.nn
as
nn
import
paddle.vision.models.vgg
as
vgg
...
...
ppgan/models/generators/basicvsr.py
浏览文件 @
2328f9fb
# Copyright (c) 2021 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.
# Copyright (c) MMEditing Authors.
import
paddle
...
...
ppgan/models/generators/deoldify.py
浏览文件 @
2328f9fb
# 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.
# MIT License
# Copyright (c) 2018 Jason Antic
import
numpy
as
np
import
paddle
...
...
ppgan/models/ugatit_model.py
浏览文件 @
2328f9fb
...
...
@@ -48,8 +48,18 @@ class UGATITModel(BaseModel):
cam_weight
=
1000.0
):
"""Initialize the CycleGAN class.
Parameters:
opt (config)-- stores all the experiment flags; needs to be a subclass of Dict
Args:
generator (dict): config of generator.
discriminator_g (dict): config of discriminator_g.
discriminator_l (dict): config of discriminator_l.
l1_criterion (dict): config of l1_criterion.
mse_criterion (dict): config of mse_criterion.
bce_criterion (dict): config of bce_criterion.
direction (str): direction of dataset, default: 'a2b'.
adv_weight (float): adversial loss weight, default: 1.0.
cycle_weight (float): cycle loss weight, default: 10.0.
identity_weight (float): identity loss weight, default: 10.0.
cam_weight (float): cam loss weight, default: 1000.0.
"""
super
(
UGATITModel
,
self
).
__init__
()
self
.
adv_weight
=
adv_weight
...
...
ppgan/utils/animate.py
浏览文件 @
2328f9fb
...
...
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# code was heavily based on https://github.com/AliaksandrSiarohin/first-order-model
import
numpy
as
np
from
scipy.spatial
import
ConvexHull
...
...
ppgan/utils/audio.py
浏览文件 @
2328f9fb
# code was heavily based on https://github.com/Rudrabha/Wav2Lip
# Users should be careful about adopting these functions in any commercial matters.
# https://github.com/Rudrabha/Wav2Lip#license-and-citation
import
numpy
as
np
from
scipy
import
signal
from
scipy.io
import
wavfile
...
...
ppgan/utils/audio_config.py
浏览文件 @
2328f9fb
from
easydict
import
EasyDict
as
ed
ict
from
.config
import
AttrD
ict
_
C
=
ed
ict
()
_
audio_cfg
=
AttrD
ict
()
_
C
.
num_mels
=
80
_
C
.
rescale
=
True
_
C
.
rescaling_max
=
0.9
_
C
.
use_lws
=
False
_
C
.
n_fft
=
800
_
C
.
hop_size
=
200
_
C
.
win_size
=
800
_
C
.
sample_rate
=
16000
_
C
.
frame_shift_ms
=
None
_
C
.
signal_normalization
=
True
_
C
.
allow_clipping_in_normalization
=
True
_
C
.
symmetric_mels
=
True
_
C
.
max_abs_value
=
4.
_
C
.
preemphasize
=
True
_
C
.
preemphasis
=
0.97
_
C
.
min_level_db
=
-
100
_
C
.
ref_level_db
=
20
_
C
.
fmin
=
55
_
C
.
fmax
=
7600
_
C
.
fps
=
25
_
audio_cfg
.
num_mels
=
80
_
audio_cfg
.
rescale
=
True
_
audio_cfg
.
rescaling_max
=
0.9
_
audio_cfg
.
use_lws
=
False
_
audio_cfg
.
n_fft
=
800
_
audio_cfg
.
hop_size
=
200
_
audio_cfg
.
win_size
=
800
_
audio_cfg
.
sample_rate
=
16000
_
audio_cfg
.
frame_shift_ms
=
None
_
audio_cfg
.
signal_normalization
=
True
_
audio_cfg
.
allow_clipping_in_normalization
=
True
_
audio_cfg
.
symmetric_mels
=
True
_
audio_cfg
.
max_abs_value
=
4.
_
audio_cfg
.
preemphasize
=
True
_
audio_cfg
.
preemphasis
=
0.97
_
audio_cfg
.
min_level_db
=
-
100
_
audio_cfg
.
ref_level_db
=
20
_
audio_cfg
.
fmin
=
55
_
audio_cfg
.
fmax
=
7600
_
audio_cfg
.
fps
=
25
def
get_audio_config
():
return
_
C
return
_
audio_cfg
ppgan/utils/config.py
浏览文件 @
2328f9fb
...
...
@@ -19,7 +19,6 @@ __all__ = ['get_config']
class
AttrDict
(
dict
):
def
__getattr__
(
self
,
key
):
# return self[key]
try
:
return
self
[
key
]
except
KeyError
:
...
...
ppgan/utils/image_pool.py
浏览文件 @
2328f9fb
...
...
@@ -21,51 +21,48 @@ 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
Parameters:
pool_size (int) -- the size of image buffer, if pool_size=0, no buffer will be created
"""
Args:
pool_size (int) -- the size of image buffer, if pool_size=0, no buffer will be created
"""
def
__init__
(
self
,
pool_size
,
prob
=
0.5
):
self
.
pool_size
=
pool_size
if
self
.
pool_size
>
0
:
# create an empty pool
self
.
prob
=
prob
if
self
.
pool_size
>
0
:
self
.
num_imgs
=
0
self
.
images
=
[]
def
query
(
self
,
images
):
"""Return an image from the pool.
Parameter
s:
images: the latest generated images from the generator
Arg
s:
images
(paddle.Tensor)
: the latest generated images from the generator
Returns images from the buffer.
By 50/100, the buffer will return input images.
By 50/100, the buffer will return images previously stored in the buffer,
and insert the current images to the buffer.
"""
if
self
.
pool_size
==
0
:
# if the buffer size is 0, do nothing
# if the buffer size is 0, do nothing
if
self
.
pool_size
==
0
:
return
images
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 the buffer is not full; keep inserting current images to the buffer
if
self
.
num_imgs
<
self
.
pool_size
:
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
# FIXME: clone
# tmp = (self.images[random_id]).detach() #.clone()
tmp
=
self
.
images
[
random_id
]
#.clone()
# by 50% chance, the buffer will return a previously stored image, and insert the current image into the buffer
if
p
>
self
.
prob
:
random_id
=
random
.
randint
(
0
,
self
.
pool_size
-
1
)
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
# collect all the images and return
return_images
=
paddle
.
concat
(
return_images
,
0
)
return
return_images
ppgan/utils/logger.py
浏览文件 @
2328f9fb
...
...
@@ -61,10 +61,9 @@ def setup_logger(output=None, name="ppgan"):
if
local_rank
>
0
:
filename
=
filename
+
".rank{}"
.
format
(
local_rank
)
#
PathManager.mkdirs(os.path.dirname(filename))
#
make dir if path not exist
os
.
makedirs
(
os
.
path
.
dirname
(
filename
),
exist_ok
=
True
)
# fh = logging.StreamHandler(_cached_log_stream(filename)
fh
=
logging
.
FileHandler
(
filename
,
mode
=
'a'
)
fh
.
setLevel
(
logging
.
DEBUG
)
fh
.
setFormatter
(
plain_formatter
)
...
...
ppgan/utils/registry.py
浏览文件 @
2328f9fb
...
...
@@ -77,6 +77,8 @@ class Registry(object):
return
ret
# code was based on mmcv
# Copyright (c) Copyright (c) OpenMMLab.
def
build_from_config
(
cfg
,
registry
,
default_args
=
None
):
"""Build a class from config dict.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录