Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
e93c01e4
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
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看板
提交
e93c01e4
编写于
10月 30, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename paddlehub.process -> paddlehub.transforms
上级
1ed226af
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
70 addition
and
59 deletion
+70
-59
demo/colorization/predict.py
demo/colorization/predict.py
+1
-1
demo/colorization/train.py
demo/colorization/train.py
+1
-1
demo/image_classification/train.py
demo/image_classification/train.py
+1
-1
demo/style_transfer/train.py
demo/style_transfer/train.py
+1
-1
modules/image/colorization/user_guided_colorization/module.py
...les/image/colorization/user_guided_colorization/module.py
+1
-1
modules/image/keypoint_detection/openpose_body_estimation/module.py
...age/keypoint_detection/openpose_body_estimation/module.py
+10
-8
modules/image/keypoint_detection/openpose_hands_estimation/module.py
...ge/keypoint_detection/openpose_hands_estimation/module.py
+9
-7
modules/image/style_transfer/msgnet/module.py
modules/image/style_transfer/msgnet/module.py
+16
-16
paddlehub/datasets/canvas.py
paddlehub/datasets/canvas.py
+1
-1
paddlehub/datasets/minicoco.py
paddlehub/datasets/minicoco.py
+1
-1
paddlehub/module/cv_module.py
paddlehub/module/cv_module.py
+2
-2
paddlehub/transforms/detect_transforms.py
paddlehub/transforms/detect_transforms.py
+10
-5
paddlehub/transforms/functional.py
paddlehub/transforms/functional.py
+0
-0
paddlehub/transforms/transforms.py
paddlehub/transforms/transforms.py
+16
-14
未找到文件。
demo/colorization/predict.py
浏览文件 @
e93c01e4
...
...
@@ -2,5 +2,5 @@ import paddle
import
paddlehub
as
hub
if
__name__
==
'__main__'
:
model
=
hub
.
Module
(
name
=
'user_guided_colorization'
,
load_checkpoint
=
'/PATH/TO/CHECKPOINT'
)
model
=
hub
.
Module
(
name
=
'user_guided_colorization'
)
result
=
model
.
predict
(
images
=
'house.png'
)
demo/colorization/train.py
浏览文件 @
e93c01e4
import
paddle
import
paddlehub
as
hub
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
transform
s.transforms
as
T
from
paddlehub.finetune.trainer
import
Trainer
from
paddlehub.datasets
import
Canvas
...
...
demo/image_classification/train.py
浏览文件 @
e93c01e4
import
paddle
import
paddlehub
as
hub
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
transform
s.transforms
as
T
from
paddlehub.finetune.trainer
import
Trainer
from
paddlehub.datasets
import
Flowers
...
...
demo/style_transfer/train.py
浏览文件 @
e93c01e4
import
paddle
import
paddlehub
as
hub
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
transform
s.transforms
as
T
from
paddlehub.finetune.trainer
import
Trainer
from
paddlehub.datasets
import
MiniCOCO
...
...
modules/image/colorization/user_guided_colorization/module.py
浏览文件 @
e93c01e4
...
...
@@ -18,7 +18,7 @@ import paddle
import
paddle.nn
as
nn
from
paddle.nn
import
Conv2D
,
Conv2DTranspose
from
paddlehub.module.module
import
moduleinfo
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
transform
s.transforms
as
T
from
paddlehub.module.cv_module
import
ImageColorizeModule
from
user_guided_colorization.data_feed
import
ColorizePreprocess
...
...
modules/image/keypoint_detection/openpose_body_estimation/module.py
浏览文件 @
e93c01e4
...
...
@@ -20,18 +20,19 @@ import cv2
import
paddle
import
paddle.nn
as
nn
import
numpy
as
np
from
paddlehub.
module
.module
import
moduleinfo
import
paddlehub.
proces
s.transforms
as
T
from
paddlehub.
transforms
.module
import
moduleinfo
import
paddlehub.
transform
s.transforms
as
T
import
openpose_body_estimation.processor
as
P
@
moduleinfo
(
name
=
"openpose_body_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
summary
=
"Openpose_body_estimation is a body pose estimation model based on Realtime Multi-Person 2D Pose
\
@
moduleinfo
(
name
=
"openpose_body_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
summary
=
"Openpose_body_estimation is a body pose estimation model based on Realtime Multi-Person 2D Pose
\
Estimation using Part Affinity Fields."
,
version
=
"1.0.0"
)
version
=
"1.0.0"
)
class
BodyPoseModel
(
nn
.
Layer
):
"""
BodyposeModel
...
...
@@ -40,6 +41,7 @@ class BodyPoseModel(nn.Layer):
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__
()
...
...
modules/image/keypoint_detection/openpose_hands_estimation/module.py
浏览文件 @
e93c01e4
...
...
@@ -25,18 +25,19 @@ from skimage.measure import label
from
scipy.ndimage.filters
import
gaussian_filter
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.process.functional
import
npmax
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
transform
s.transforms
as
T
import
openpose_hands_estimation.processor
as
P
@
moduleinfo
(
name
=
"openpose_hands_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
summary
=
"Openpose_hands_estimation is a hand pose estimation model based on Hand Keypoint Detection in
\
@
moduleinfo
(
name
=
"openpose_hands_estimation"
,
type
=
"CV/image_editing"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
summary
=
"Openpose_hands_estimation is a hand pose estimation model based on Hand Keypoint Detection in
\
Single Images using Multiview Bootstrapping."
,
version
=
"1.0.0"
)
version
=
"1.0.0"
)
class
HandPoseModel
(
nn
.
Layer
):
"""
HandposeModel
...
...
@@ -45,6 +46,7 @@ class HandPoseModel(nn.Layer):
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
...
...
modules/image/style_transfer/msgnet/module.py
浏览文件 @
e93c01e4
...
...
@@ -7,12 +7,13 @@ import paddle.nn.functional as F
from
paddlehub.env
import
MODULE_HOME
from
paddlehub.module.module
import
moduleinfo
from
paddlehub.
proces
s.transforms
import
Compose
,
Resize
,
CenterCrop
,
SetType
from
paddlehub.
transform
s.transforms
import
Compose
,
Resize
,
CenterCrop
,
SetType
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
))
...
...
@@ -23,6 +24,7 @@ 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
))
...
...
@@ -50,6 +52,7 @@ 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
...
...
@@ -84,6 +87,7 @@ class Bottleneck(nn.Layer):
Return:
img(paddle.Tensor): Bottleneck output.
"""
def
__init__
(
self
,
inplanes
:
int
,
planes
:
int
,
...
...
@@ -97,8 +101,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
):
...
...
@@ -124,14 +128,12 @@ 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
+=
[
...
...
@@ -162,6 +164,7 @@ class Inspiration(nn.Layer):
Return:
img(paddle.Tensor): UpBottleneck output.
"""
def
__init__
(
self
,
C
:
int
,
B
:
int
=
1
):
super
(
Inspiration
,
self
).
__init__
()
...
...
@@ -178,8 +181,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
):
...
...
@@ -189,6 +192,7 @@ 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
)
...
...
@@ -263,12 +267,8 @@ 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
()
...
...
paddlehub/datasets/canvas.py
浏览文件 @
e93c01e4
...
...
@@ -18,7 +18,7 @@ import os
import
numpy
as
np
import
paddle
from
paddlehub.
proces
s.functional
import
get_img_file
from
paddlehub.
transform
s.functional
import
get_img_file
from
paddlehub.env
import
DATA_HOME
from
typing
import
Callable
from
paddlehub.utils.download
import
download_data
...
...
paddlehub/datasets/minicoco.py
浏览文件 @
e93c01e4
...
...
@@ -17,7 +17,7 @@ import os
from
typing
import
Callable
import
paddle
from
paddlehub.
proces
s.functional
import
get_img_file
from
paddlehub.
transform
s.functional
import
get_img_file
from
paddlehub.env
import
DATA_HOME
from
paddlehub.utils.download
import
download_data
...
...
paddlehub/module/cv_module.py
浏览文件 @
e93c01e4
...
...
@@ -27,8 +27,8 @@ from PIL import Image
from
paddlehub.module.module
import
serving
,
RunModule
from
paddlehub.utils.utils
import
base64_to_cv2
import
paddlehub.
proces
s.transforms
as
T
import
paddlehub.
proces
s.functional
as
Func
import
paddlehub.
transform
s.transforms
as
T
import
paddlehub.
transform
s.functional
as
Func
class
ImageServing
(
object
):
...
...
paddlehub/
proces
s/detect_transforms.py
→
paddlehub/
transform
s/detect_transforms.py
浏览文件 @
e93c01e4
...
...
@@ -9,7 +9,7 @@ import PIL
from
PIL
import
Image
,
ImageEnhance
from
matplotlib
import
pyplot
as
plt
from
paddlehub.
proces
s.functional
import
*
from
paddlehub.
transform
s.functional
import
*
matplotlib
.
use
(
'Agg'
)
...
...
@@ -27,6 +27,7 @@ class RandomDistort:
data(dict): Image info and label info.
"""
def
__init__
(
self
,
lower
:
float
=
0.5
,
upper
:
float
=
1.5
):
self
.
lower
=
lower
self
.
upper
=
upper
...
...
@@ -70,6 +71,7 @@ class RandomExpand:
data(dict): Image info and label info.
"""
def
__init__
(
self
,
max_ratio
:
float
=
4.
,
fill
:
list
=
None
,
keep_ratio
:
bool
=
True
,
thresh
:
float
=
0.5
):
self
.
max_ratio
=
max_ratio
...
...
@@ -129,10 +131,8 @@ class RandomCrop:
data(dict): Image info and label info.
"""
def
__init__
(
self
,
scales
:
list
=
[
0.3
,
1.0
],
max_ratio
:
float
=
2.0
,
constraints
:
list
=
None
,
def
__init__
(
self
,
scales
:
list
=
[
0.3
,
1.0
],
max_ratio
:
float
=
2.0
,
constraints
:
list
=
None
,
max_trial
:
int
=
50
):
self
.
scales
=
scales
self
.
max_ratio
=
max_ratio
...
...
@@ -198,6 +198,7 @@ class RandomFlip:
img(np.ndarray): Distorted image.
data(dict): Image info and label info.
"""
def
__init__
(
self
,
thresh
:
float
=
0.5
):
self
.
thresh
=
thresh
...
...
@@ -221,6 +222,7 @@ class Compose:
img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None.
"""
def
__init__
(
self
,
transforms
:
list
):
if
not
isinstance
(
transforms
,
list
):
raise
TypeError
(
'The transforms must be a list!'
)
...
...
@@ -263,6 +265,7 @@ class Resize:
img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None.
"""
def
__init__
(
self
,
target_size
:
int
=
512
,
interp
:
str
=
'RANDOM'
):
self
.
interp_dict
=
{
'NEAREST'
:
cv2
.
INTER_NEAREST
,
...
...
@@ -309,6 +312,7 @@ class Normalize:
img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None.
"""
def
__init__
(
self
,
mean
=
[
0.5
,
0.5
,
0.5
],
std
=
[
0.5
,
0.5
,
0.5
]):
self
.
mean
=
mean
self
.
std
=
std
...
...
@@ -332,6 +336,7 @@ class Normalize:
class
ShuffleBox
:
"""Shuffle detection information for corresponding input image."""
def
__call__
(
self
,
img
,
data
):
gt
=
np
.
concatenate
([
data
[
'gt_boxes'
],
data
[
'gt_labels'
][:,
np
.
newaxis
],
data
[
'gt_scores'
][:,
np
.
newaxis
]],
axis
=
1
)
...
...
paddlehub/
proces
s/functional.py
→
paddlehub/
transform
s/functional.py
浏览文件 @
e93c01e4
文件已移动
paddlehub/
proces
s/transforms.py
→
paddlehub/
transform
s/transforms.py
浏览文件 @
e93c01e4
...
...
@@ -29,7 +29,7 @@ from matplotlib import pyplot as plt
from
matplotlib.figure
import
Figure
from
scipy.ndimage.filters
import
gaussian_filter
from
matplotlib.backends.backend_agg
import
FigureCanvasAgg
as
FigureCanvas
from
paddlehub.
proces
s.functional
import
*
from
paddlehub.
transform
s.functional
import
*
matplotlib
.
use
(
'Agg'
)
...
...
@@ -252,13 +252,8 @@ class RandomPaddingCrop:
pad_height
=
max
(
crop_height
-
img_height
,
0
)
pad_width
=
max
(
crop_width
-
img_width
,
0
)
if
(
pad_height
>
0
or
pad_width
>
0
):
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
im
=
cv2
.
copyMakeBorder
(
im
,
0
,
pad_height
,
0
,
pad_width
,
cv2
.
BORDER_CONSTANT
,
value
=
self
.
im_padding_value
)
if
crop_height
>
0
and
crop_width
>
0
:
h_off
=
np
.
random
.
randint
(
img_height
-
crop_height
+
1
)
...
...
@@ -313,12 +308,13 @@ class RandomRotation:
r
[
0
,
2
]
+=
(
nw
/
2
)
-
cx
r
[
1
,
2
]
+=
(
nh
/
2
)
-
cy
dsize
=
(
nw
,
nh
)
im
=
cv2
.
warpAffine
(
im
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_LINEAR
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
im_padding_value
)
im
=
cv2
.
warpAffine
(
im
,
r
,
dsize
=
dsize
,
flags
=
cv2
.
INTER_LINEAR
,
borderMode
=
cv2
.
BORDER_CONSTANT
,
borderValue
=
self
.
im_padding_value
)
return
im
...
...
@@ -425,6 +421,7 @@ class RGB2LAB:
"""
Convert color space from RGB to LAB.
"""
def
rgb2xyz
(
self
,
rgb
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Convert color space from RGB to XYZ.
...
...
@@ -491,6 +488,7 @@ class LAB2RGB:
"""
Convert color space from LAB to RGB.
"""
def
__init__
(
self
,
mode
:
str
=
'RGB2LAB'
):
self
.
mode
=
mode
...
...
@@ -568,6 +566,7 @@ class ColorPostprocess:
Return:
img(np.ndarray): Image in range of 0-255.
"""
def
__init__
(
self
,
type
:
type
=
np
.
uint8
):
self
.
type
=
type
...
...
@@ -588,6 +587,7 @@ class CenterCrop:
Return:
img(np.ndarray): Croped image.
"""
def
__init__
(
self
,
crop_size
:
int
):
self
.
crop_size
=
crop_size
...
...
@@ -608,6 +608,7 @@ class SetType:
Return:
img(np.ndarray): Transformed image.
"""
def
__init__
(
self
,
datatype
:
type
=
'float32'
):
self
.
type
=
datatype
...
...
@@ -623,6 +624,7 @@ class ResizeScaling:
target(int): Target image size.
interp(Callable): Interpolation method.
"""
def
__init__
(
self
,
target
:
int
=
368
,
interp
:
Callable
=
cv2
.
INTER_CUBIC
):
self
.
target
=
target
self
.
interp
=
interp
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录