Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
4dc6f237
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 2 年 前同步成功
通知
285
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4dc6f237
编写于
10月 30, 2020
作者:
H
haoyuying
提交者:
GitHub
10月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt openpose to rc version
上级
6f153ddc
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
44 addition
and
72 deletion
+44
-72
modules/image/keypoint_detection/openpose_body_estimation/module.py
...age/keypoint_detection/openpose_body_estimation/module.py
+14
-28
modules/image/keypoint_detection/openpose_hands_estimation/module.py
...ge/keypoint_detection/openpose_hands_estimation/module.py
+15
-26
modules/image/style_transfer/msgnet/module.py
modules/image/style_transfer/msgnet/module.py
+15
-18
未找到文件。
modules/image/keypoint_detection/openpose_body_estimation/module.py
浏览文件 @
4dc6f237
# coding:utf-8
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# 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
#
...
...
@@ -23,12 +22,10 @@ import paddle.nn as nn
import
numpy
as
np
from
paddlehub.module.module
import
moduleinfo
import
paddlehub.process.transforms
as
T
import
openpose_body_estimation.processor
as
P
@
moduleinfo
(
name
=
"openpose_body_estimation"
,
@
moduleinfo
(
name
=
"openpose_body_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
...
...
@@ -37,13 +34,12 @@ import openpose_body_estimation.processor as P
version
=
"1.0.0"
)
class
BodyPoseModel
(
nn
.
Layer
):
"""
Body
P
oseModel
Body
p
oseModel
Args:
load_checkpoint(str): Checkpoint save path, default is None.
visualization (bool): Whether to save the estimation result. Default is True.
"""
def
__init__
(
self
,
load_checkpoint
:
str
=
None
,
visualization
:
bool
=
True
):
super
(
BodyPoseModel
,
self
).
__init__
()
...
...
@@ -118,15 +114,13 @@ class BodyPoseModel(nn.Layer):
self
.
model6_2
=
blocks
[
'block6_2'
]
if
load_checkpoint
is
not
None
:
model_dict
=
paddle
.
load
(
load_checkpoint
)
[
0
]
model_dict
=
paddle
.
load
(
load_checkpoint
)
self
.
set_dict
(
model_dict
)
print
(
"load custom checkpoint success"
)
else
:
checkpoint
=
os
.
path
.
join
(
self
.
directory
,
'openpose_body.pdparams'
)
if
not
os
.
path
.
exists
(
checkpoint
):
os
.
system
(
'wget https://paddlehub.bj.bcebos.com/dygraph/pose/openpose_body.pdparams -O '
+
checkpoint
)
model_dict
=
paddle
.
load
(
checkpoint
)[
0
]
model_dict
=
paddle
.
load
(
checkpoint
)
self
.
set_dict
(
model_dict
)
print
(
"load pretrained checkpoint success"
)
...
...
@@ -134,10 +128,10 @@ class BodyPoseModel(nn.Layer):
layers
=
[]
for
layer_name
,
v
in
block
.
items
():
if
'pool'
in
layer_name
:
layer
=
nn
.
MaxPool2
d
(
kernel_size
=
v
[
0
],
stride
=
v
[
1
],
padding
=
v
[
2
])
layer
=
nn
.
MaxPool2
D
(
kernel_size
=
v
[
0
],
stride
=
v
[
1
],
padding
=
v
[
2
])
layers
.
append
((
layer_name
,
layer
))
else
:
conv2d
=
nn
.
Conv2
d
(
in_channels
=
v
[
0
],
out_channels
=
v
[
1
],
kernel_size
=
v
[
2
],
stride
=
v
[
3
],
padding
=
v
[
4
])
conv2d
=
nn
.
Conv2
D
(
in_channels
=
v
[
0
],
out_channels
=
v
[
1
],
kernel_size
=
v
[
2
],
stride
=
v
[
3
],
padding
=
v
[
4
])
layers
.
append
((
layer_name
,
conv2d
))
if
layer_name
not
in
no_relu_layers
:
layers
.
append
((
'relu_'
+
layer_name
,
nn
.
ReLU
()))
...
...
@@ -204,11 +198,3 @@ class BodyPoseModel(nn.Layer):
save_path
=
os
.
path
.
join
(
save_path
,
img_path
.
rsplit
(
"/"
,
1
)[
-
1
])
cv2
.
imwrite
(
save_path
,
canvas
)
return
candidate
,
subset
if
__name__
==
"__main__"
:
paddle
.
disable_static
()
model
=
BodyPoseModel
()
model
.
eval
()
out1
,
out2
=
model
.
predict
(
"demo.jpg"
)
modules/image/keypoint_detection/openpose_hands_estimation/module.py
浏览文件 @
4dc6f237
# coding:utf-8
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# 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
#
...
...
@@ -31,8 +30,7 @@ import paddlehub.process.transforms as T
import
openpose_hands_estimation.processor
as
P
@
moduleinfo
(
name
=
"openpose_hands_estimation"
,
@
moduleinfo
(
name
=
"openpose_hands_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
...
...
@@ -41,17 +39,16 @@ import openpose_hands_estimation.processor as P
version
=
"1.0.0"
)
class
HandPoseModel
(
nn
.
Layer
):
"""
Hand
P
oseModel
Hand
p
oseModel
Args:
load_checkpoint(str): Checkpoint save path, default is None.
visualization (bool): Whether to save the estimation result. Default is True.
"""
def
__init__
(
self
,
load_checkpoint
:
str
=
None
,
visualization
:
bool
=
True
):
super
(
HandPoseModel
,
self
).
__init__
()
self
.
visualization
=
visualization
self
.
resize_func
=
T
.
ResizeScaling
()
self
.
norm_func
=
T
.
Normalize
(
std
=
[
1
,
1
,
1
])
self
.
hand_detect
=
P
.
HandDetect
()
...
...
@@ -59,6 +56,7 @@ class HandPoseModel(nn.Layer):
self
.
remove_pad
=
P
.
RemovePadding
()
self
.
draw_pose
=
P
.
DrawPose
()
self
.
draw_hand
=
P
.
DrawHandPose
()
no_relu_layers
=
[
'conv6_2_CPM'
,
'Mconv7_stage2'
,
'Mconv7_stage3'
,
\
'Mconv7_stage4'
,
'Mconv7_stage5'
,
'Mconv7_stage6'
]
...
...
@@ -105,9 +103,7 @@ class HandPoseModel(nn.Layer):
else
:
checkpoint
=
os
.
path
.
join
(
self
.
directory
,
'openpose_hand.pdparams'
)
if
not
os
.
path
.
exists
(
checkpoint
):
os
.
system
(
'wget https://paddlehub.bj.bcebos.com/dygraph/pose/openpose_hand.pdparams -O '
+
checkpoint
)
model_dict
=
paddle
.
load
(
checkpoint
)[
0
]
model_dict
=
paddle
.
load
(
checkpoint
)
self
.
set_dict
(
model_dict
)
print
(
"load pretrained checkpoint success"
)
...
...
@@ -115,10 +111,10 @@ class HandPoseModel(nn.Layer):
layers
=
[]
for
layer_name
,
v
in
block
.
items
():
if
'pool'
in
layer_name
:
layer
=
nn
.
MaxPool2
d
(
kernel_size
=
v
[
0
],
stride
=
v
[
1
],
padding
=
v
[
2
])
layer
=
nn
.
MaxPool2
D
(
kernel_size
=
v
[
0
],
stride
=
v
[
1
],
padding
=
v
[
2
])
layers
.
append
((
layer_name
,
layer
))
else
:
conv2d
=
nn
.
Conv2
d
(
in_channels
=
v
[
0
],
out_channels
=
v
[
1
],
kernel_size
=
v
[
2
],
stride
=
v
[
3
],
padding
=
v
[
4
])
conv2d
=
nn
.
Conv2
D
(
in_channels
=
v
[
0
],
out_channels
=
v
[
1
],
kernel_size
=
v
[
2
],
stride
=
v
[
3
],
padding
=
v
[
4
])
layers
.
append
((
layer_name
,
conv2d
))
if
layer_name
not
in
no_relu_layers
:
layers
.
append
((
'relu_'
+
layer_name
,
nn
.
ReLU
()))
...
...
@@ -197,10 +193,3 @@ class HandPoseModel(nn.Layer):
save_path
=
os
.
path
.
join
(
save_path
,
img_path
.
rsplit
(
"/"
,
1
)[
-
1
])
cv2
.
imwrite
(
save_path
,
canvas
)
return
all_hand_peaks
if
__name__
==
"__main__"
:
paddle
.
disable_static
()
model
=
HandPoseModel
()
model
.
eval
()
out1
=
model
.
predict
(
"detect_hand4.jpg"
)
modules/image/style_transfer/msgnet/module.py
浏览文件 @
4dc6f237
...
...
@@ -13,7 +13,6 @@ from paddlehub.module.cv_module import StyleTransferModule
class
GramMatrix
(
nn
.
Layer
):
"""Calculate gram matrix"""
def
forward
(
self
,
y
):
(
b
,
ch
,
h
,
w
)
=
y
.
shape
features
=
y
.
reshape
((
b
,
ch
,
w
*
h
))
...
...
@@ -24,7 +23,6 @@ class GramMatrix(nn.Layer):
class
ConvLayer
(
nn
.
Layer
):
"""Basic conv layer with reflection padding layer"""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
stride
:
int
):
super
(
ConvLayer
,
self
).
__init__
()
pad
=
int
(
np
.
floor
(
kernel_size
/
2
))
...
...
@@ -52,7 +50,6 @@ class UpsampleConvLayer(nn.Layer):
Return:
img(paddle.Tensor): UpsampleConvLayer output.
"""
def
__init__
(
self
,
in_channels
:
int
,
out_channels
:
int
,
kernel_size
:
int
,
stride
:
int
,
upsample
=
None
):
super
(
UpsampleConvLayer
,
self
).
__init__
()
self
.
upsample
=
upsample
...
...
@@ -87,7 +84,6 @@ class Bottleneck(nn.Layer):
Return:
img(paddle.Tensor): Bottleneck output.
"""
def
__init__
(
self
,
inplanes
:
int
,
planes
:
int
,
...
...
@@ -101,8 +97,8 @@ class Bottleneck(nn.Layer):
self
.
residual_layer
=
nn
.
Conv2D
(
inplanes
,
planes
*
self
.
expansion
,
kernel_size
=
1
,
stride
=
stride
)
conv_block
=
(
norm_layer
(
inplanes
),
nn
.
ReLU
(),
nn
.
Conv2D
(
inplanes
,
planes
,
kernel_size
=
1
,
stride
=
1
),
norm_layer
(
planes
),
nn
.
ReLU
(),
ConvLayer
(
planes
,
planes
,
kernel_size
=
3
,
stride
=
stride
),
norm_layer
(
planes
),
nn
.
ReLU
(),
nn
.
Conv2D
(
planes
,
planes
*
self
.
expansion
,
kernel_size
=
1
,
stride
=
1
))
norm_layer
(
planes
),
nn
.
ReLU
(),
nn
.
Conv2D
(
planes
,
planes
*
self
.
expansion
,
kernel_size
=
1
,
stride
=
1
))
self
.
conv_block
=
nn
.
Sequential
(
*
conv_block
)
def
forward
(
self
,
x
:
paddle
.
Tensor
):
...
...
@@ -128,12 +124,14 @@ class UpBottleneck(nn.Layer):
Return:
img(paddle.Tensor): UpBottleneck output.
"""
def
__init__
(
self
,
inplanes
:
int
,
planes
:
int
,
stride
:
int
=
2
,
norm_layer
:
nn
.
Layer
=
nn
.
BatchNorm2D
):
super
(
UpBottleneck
,
self
).
__init__
()
self
.
expansion
=
4
self
.
residual_layer
=
UpsampleConvLayer
(
inplanes
,
planes
*
self
.
expansion
,
kernel_size
=
1
,
stride
=
1
,
upsample
=
stride
)
self
.
residual_layer
=
UpsampleConvLayer
(
inplanes
,
planes
*
self
.
expansion
,
kernel_size
=
1
,
stride
=
1
,
upsample
=
stride
)
conv_block
=
[]
conv_block
+=
[
norm_layer
(
inplanes
),
nn
.
ReLU
(),
nn
.
Conv2D
(
inplanes
,
planes
,
kernel_size
=
1
,
stride
=
1
)]
conv_block
+=
[
...
...
@@ -164,7 +162,6 @@ class Inspiration(nn.Layer):
Return:
img(paddle.Tensor): UpBottleneck output.
"""
def
__init__
(
self
,
C
:
int
,
B
:
int
=
1
):
super
(
Inspiration
,
self
).
__init__
()
...
...
@@ -181,8 +178,8 @@ class Inspiration(nn.Layer):
self
.
P
=
paddle
.
bmm
(
self
.
weight
.
expand_as
(
self
.
G
),
self
.
G
)
x
=
paddle
.
bmm
(
self
.
P
.
transpose
((
0
,
2
,
1
)).
expand
((
X
.
shape
[
0
],
self
.
C
,
self
.
C
)),
X
.
reshape
(
(
X
.
shape
[
0
],
X
.
shape
[
1
],
-
1
))).
reshape
(
X
.
shape
)
self
.
P
.
transpose
((
0
,
2
,
1
)).
expand
((
X
.
shape
[
0
],
self
.
C
,
self
.
C
)),
X
.
reshape
(
(
X
.
shape
[
0
],
X
.
shape
[
1
],
-
1
))).
reshape
(
X
.
shape
)
return
x
def
__repr__
(
self
):
...
...
@@ -192,7 +189,6 @@ class Inspiration(nn.Layer):
class
Vgg16
(
nn
.
Layer
):
""" First four layers from Vgg16."""
def
__init__
(
self
):
super
(
Vgg16
,
self
).
__init__
()
self
.
conv1_1
=
nn
.
Conv2D
(
3
,
64
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
...
...
@@ -214,9 +210,6 @@ class Vgg16(nn.Layer):
self
.
conv5_3
=
nn
.
Conv2D
(
512
,
512
,
kernel_size
=
3
,
stride
=
1
,
padding
=
1
)
checkpoint
=
os
.
path
.
join
(
MODULE_HOME
,
'msgnet'
,
'vgg16.pdparams'
)
if
not
os
.
path
.
exists
(
checkpoint
):
os
.
system
(
'wget https://bj.bcebos.com/paddlehub/model/image/image_editing/vgg_paddle.pdparams -O '
+
checkpoint
)
model_dict
=
paddle
.
load
(
checkpoint
)
self
.
set_dict
(
model_dict
)
print
(
"load pretrained vgg16 checkpoint success"
)
...
...
@@ -270,8 +263,12 @@ class MSGNet(nn.Layer):
Return:
img(paddle.Tensor): MSGNet output.
"""
def
__init__
(
self
,
input_nc
=
3
,
output_nc
=
3
,
ngf
=
128
,
n_blocks
=
6
,
norm_layer
=
nn
.
InstanceNorm2D
,
def
__init__
(
self
,
input_nc
=
3
,
output_nc
=
3
,
ngf
=
128
,
n_blocks
=
6
,
norm_layer
=
nn
.
InstanceNorm2D
,
load_checkpoint
=
None
):
super
(
MSGNet
,
self
).
__init__
()
self
.
gram
=
GramMatrix
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录