提交 e93c01e4 编写于 作者: W wuzewu

Rename paddlehub.process -> paddlehub.transforms

上级 1ed226af
...@@ -2,5 +2,5 @@ import paddle ...@@ -2,5 +2,5 @@ import paddle
import paddlehub as hub import paddlehub as hub
if __name__ == '__main__': 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') result = model.predict(images='house.png')
import paddle import paddle
import paddlehub as hub import paddlehub as hub
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import Canvas from paddlehub.datasets import Canvas
......
import paddle import paddle
import paddlehub as hub import paddlehub as hub
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import Flowers from paddlehub.datasets import Flowers
......
import paddle import paddle
import paddlehub as hub import paddlehub as hub
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import MiniCOCO from paddlehub.datasets import MiniCOCO
......
...@@ -18,7 +18,7 @@ import paddle ...@@ -18,7 +18,7 @@ import paddle
import paddle.nn as nn import paddle.nn as nn
from paddle.nn import Conv2D, Conv2DTranspose from paddle.nn import Conv2D, Conv2DTranspose
from paddlehub.module.module import moduleinfo from paddlehub.module.module import moduleinfo
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
from paddlehub.module.cv_module import ImageColorizeModule from paddlehub.module.cv_module import ImageColorizeModule
from user_guided_colorization.data_feed import ColorizePreprocess from user_guided_colorization.data_feed import ColorizePreprocess
......
...@@ -20,18 +20,19 @@ import cv2 ...@@ -20,18 +20,19 @@ import cv2
import paddle import paddle
import paddle.nn as nn import paddle.nn as nn
import numpy as np import numpy as np
from paddlehub.module.module import moduleinfo from paddlehub.transforms.module import moduleinfo
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
import openpose_body_estimation.processor as P import openpose_body_estimation.processor as P
@moduleinfo(name="openpose_body_estimation", @moduleinfo(
type="CV/image_editing", name="openpose_body_estimation",
author="paddlepaddle", type="CV/image_editing",
author_email="", author="paddlepaddle",
summary="Openpose_body_estimation is a body pose estimation model based on Realtime Multi-Person 2D Pose \ author_email="",
summary="Openpose_body_estimation is a body pose estimation model based on Realtime Multi-Person 2D Pose \
Estimation using Part Affinity Fields.", Estimation using Part Affinity Fields.",
version="1.0.0") version="1.0.0")
class BodyPoseModel(nn.Layer): class BodyPoseModel(nn.Layer):
""" """
BodyposeModel BodyposeModel
...@@ -40,6 +41,7 @@ class BodyPoseModel(nn.Layer): ...@@ -40,6 +41,7 @@ class BodyPoseModel(nn.Layer):
load_checkpoint(str): Checkpoint save path, default is None. load_checkpoint(str): Checkpoint save path, default is None.
visualization (bool): Whether to save the estimation result. Default is True. visualization (bool): Whether to save the estimation result. Default is True.
""" """
def __init__(self, load_checkpoint: str = None, visualization: bool = True): def __init__(self, load_checkpoint: str = None, visualization: bool = True):
super(BodyPoseModel, self).__init__() super(BodyPoseModel, self).__init__()
......
...@@ -25,18 +25,19 @@ from skimage.measure import label ...@@ -25,18 +25,19 @@ from skimage.measure import label
from scipy.ndimage.filters import gaussian_filter from scipy.ndimage.filters import gaussian_filter
from paddlehub.module.module import moduleinfo from paddlehub.module.module import moduleinfo
from paddlehub.process.functional import npmax from paddlehub.process.functional import npmax
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
import openpose_hands_estimation.processor as P import openpose_hands_estimation.processor as P
@moduleinfo(name="openpose_hands_estimation", @moduleinfo(
type="CV/image_editing", name="openpose_hands_estimation",
author="paddlepaddle", type="CV/image_editing",
author_email="", author="paddlepaddle",
summary="Openpose_hands_estimation is a hand pose estimation model based on Hand Keypoint Detection in \ author_email="",
summary="Openpose_hands_estimation is a hand pose estimation model based on Hand Keypoint Detection in \
Single Images using Multiview Bootstrapping.", Single Images using Multiview Bootstrapping.",
version="1.0.0") version="1.0.0")
class HandPoseModel(nn.Layer): class HandPoseModel(nn.Layer):
""" """
HandposeModel HandposeModel
...@@ -45,6 +46,7 @@ class HandPoseModel(nn.Layer): ...@@ -45,6 +46,7 @@ class HandPoseModel(nn.Layer):
load_checkpoint(str): Checkpoint save path, default is None. load_checkpoint(str): Checkpoint save path, default is None.
visualization (bool): Whether to save the estimation result. Default is True. visualization (bool): Whether to save the estimation result. Default is True.
""" """
def __init__(self, load_checkpoint: str = None, visualization: bool = True): def __init__(self, load_checkpoint: str = None, visualization: bool = True):
super(HandPoseModel, self).__init__() super(HandPoseModel, self).__init__()
self.visualization = visualization self.visualization = visualization
......
...@@ -7,12 +7,13 @@ import paddle.nn.functional as F ...@@ -7,12 +7,13 @@ import paddle.nn.functional as F
from paddlehub.env import MODULE_HOME from paddlehub.env import MODULE_HOME
from paddlehub.module.module import moduleinfo from paddlehub.module.module import moduleinfo
from paddlehub.process.transforms import Compose, Resize, CenterCrop, SetType from paddlehub.transforms.transforms import Compose, Resize, CenterCrop, SetType
from paddlehub.module.cv_module import StyleTransferModule from paddlehub.module.cv_module import StyleTransferModule
class GramMatrix(nn.Layer): class GramMatrix(nn.Layer):
"""Calculate gram matrix""" """Calculate gram matrix"""
def forward(self, y): def forward(self, y):
(b, ch, h, w) = y.shape (b, ch, h, w) = y.shape
features = y.reshape((b, ch, w * h)) features = y.reshape((b, ch, w * h))
...@@ -23,6 +24,7 @@ class GramMatrix(nn.Layer): ...@@ -23,6 +24,7 @@ class GramMatrix(nn.Layer):
class ConvLayer(nn.Layer): class ConvLayer(nn.Layer):
"""Basic conv layer with reflection padding layer""" """Basic conv layer with reflection padding layer"""
def __init__(self, in_channels: int, out_channels: int, kernel_size: int, stride: int): def __init__(self, in_channels: int, out_channels: int, kernel_size: int, stride: int):
super(ConvLayer, self).__init__() super(ConvLayer, self).__init__()
pad = int(np.floor(kernel_size / 2)) pad = int(np.floor(kernel_size / 2))
...@@ -50,6 +52,7 @@ class UpsampleConvLayer(nn.Layer): ...@@ -50,6 +52,7 @@ class UpsampleConvLayer(nn.Layer):
Return: Return:
img(paddle.Tensor): UpsampleConvLayer output. img(paddle.Tensor): UpsampleConvLayer output.
""" """
def __init__(self, in_channels: int, out_channels: int, kernel_size: int, stride: int, upsample=None): def __init__(self, in_channels: int, out_channels: int, kernel_size: int, stride: int, upsample=None):
super(UpsampleConvLayer, self).__init__() super(UpsampleConvLayer, self).__init__()
self.upsample = upsample self.upsample = upsample
...@@ -84,6 +87,7 @@ class Bottleneck(nn.Layer): ...@@ -84,6 +87,7 @@ class Bottleneck(nn.Layer):
Return: Return:
img(paddle.Tensor): Bottleneck output. img(paddle.Tensor): Bottleneck output.
""" """
def __init__(self, def __init__(self,
inplanes: int, inplanes: int,
planes: int, planes: int,
...@@ -97,8 +101,8 @@ class Bottleneck(nn.Layer): ...@@ -97,8 +101,8 @@ class Bottleneck(nn.Layer):
self.residual_layer = nn.Conv2D(inplanes, planes * self.expansion, kernel_size=1, stride=stride) 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), 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(), ConvLayer(planes, planes, kernel_size=3, stride=stride),
norm_layer(planes), nn.ReLU(), nn.Conv2D(planes, planes * self.expansion, kernel_size=1, norm_layer(planes), nn.ReLU(), nn.Conv2D(
stride=1)) planes, planes * self.expansion, kernel_size=1, stride=1))
self.conv_block = nn.Sequential(*conv_block) self.conv_block = nn.Sequential(*conv_block)
def forward(self, x: paddle.Tensor): def forward(self, x: paddle.Tensor):
...@@ -124,14 +128,12 @@ class UpBottleneck(nn.Layer): ...@@ -124,14 +128,12 @@ class UpBottleneck(nn.Layer):
Return: Return:
img(paddle.Tensor): UpBottleneck output. img(paddle.Tensor): UpBottleneck output.
""" """
def __init__(self, inplanes: int, planes: int, stride: int = 2, norm_layer: nn.Layer = nn.BatchNorm2D): def __init__(self, inplanes: int, planes: int, stride: int = 2, norm_layer: nn.Layer = nn.BatchNorm2D):
super(UpBottleneck, self).__init__() super(UpBottleneck, self).__init__()
self.expansion = 4 self.expansion = 4
self.residual_layer = UpsampleConvLayer(inplanes, self.residual_layer = UpsampleConvLayer(
planes * self.expansion, inplanes, planes * self.expansion, kernel_size=1, stride=1, upsample=stride)
kernel_size=1,
stride=1,
upsample=stride)
conv_block = [] conv_block = []
conv_block += [norm_layer(inplanes), nn.ReLU(), nn.Conv2D(inplanes, planes, kernel_size=1, stride=1)] conv_block += [norm_layer(inplanes), nn.ReLU(), nn.Conv2D(inplanes, planes, kernel_size=1, stride=1)]
conv_block += [ conv_block += [
...@@ -162,6 +164,7 @@ class Inspiration(nn.Layer): ...@@ -162,6 +164,7 @@ class Inspiration(nn.Layer):
Return: Return:
img(paddle.Tensor): UpBottleneck output. img(paddle.Tensor): UpBottleneck output.
""" """
def __init__(self, C: int, B: int = 1): def __init__(self, C: int, B: int = 1):
super(Inspiration, self).__init__() super(Inspiration, self).__init__()
...@@ -178,8 +181,8 @@ class Inspiration(nn.Layer): ...@@ -178,8 +181,8 @@ class Inspiration(nn.Layer):
self.P = paddle.bmm(self.weight.expand_as(self.G), self.G) self.P = paddle.bmm(self.weight.expand_as(self.G), self.G)
x = paddle.bmm( x = paddle.bmm(
self.P.transpose((0, 2, 1)).expand((X.shape[0], self.C, self.C)), X.reshape( self.P.transpose((0, 2, 1)).expand((X.shape[0], self.C, self.C)), X.reshape((X.shape[0], X.shape[1],
(X.shape[0], X.shape[1], -1))).reshape(X.shape) -1))).reshape(X.shape)
return x return x
def __repr__(self): def __repr__(self):
...@@ -189,6 +192,7 @@ class Inspiration(nn.Layer): ...@@ -189,6 +192,7 @@ class Inspiration(nn.Layer):
class Vgg16(nn.Layer): class Vgg16(nn.Layer):
""" First four layers from Vgg16.""" """ First four layers from Vgg16."""
def __init__(self): def __init__(self):
super(Vgg16, self).__init__() super(Vgg16, self).__init__()
self.conv1_1 = nn.Conv2D(3, 64, kernel_size=3, stride=1, padding=1) self.conv1_1 = nn.Conv2D(3, 64, kernel_size=3, stride=1, padding=1)
...@@ -263,12 +267,8 @@ class MSGNet(nn.Layer): ...@@ -263,12 +267,8 @@ class MSGNet(nn.Layer):
Return: Return:
img(paddle.Tensor): MSGNet output. img(paddle.Tensor): MSGNet output.
""" """
def __init__(self,
input_nc=3, def __init__(self, input_nc=3, output_nc=3, ngf=128, n_blocks=6, norm_layer=nn.InstanceNorm2D,
output_nc=3,
ngf=128,
n_blocks=6,
norm_layer=nn.InstanceNorm2D,
load_checkpoint=None): load_checkpoint=None):
super(MSGNet, self).__init__() super(MSGNet, self).__init__()
self.gram = GramMatrix() self.gram = GramMatrix()
......
...@@ -18,7 +18,7 @@ import os ...@@ -18,7 +18,7 @@ import os
import numpy as np import numpy as np
import paddle import paddle
from paddlehub.process.functional import get_img_file from paddlehub.transforms.functional import get_img_file
from paddlehub.env import DATA_HOME from paddlehub.env import DATA_HOME
from typing import Callable from typing import Callable
from paddlehub.utils.download import download_data from paddlehub.utils.download import download_data
......
...@@ -17,7 +17,7 @@ import os ...@@ -17,7 +17,7 @@ import os
from typing import Callable from typing import Callable
import paddle import paddle
from paddlehub.process.functional import get_img_file from paddlehub.transforms.functional import get_img_file
from paddlehub.env import DATA_HOME from paddlehub.env import DATA_HOME
from paddlehub.utils.download import download_data from paddlehub.utils.download import download_data
......
...@@ -27,8 +27,8 @@ from PIL import Image ...@@ -27,8 +27,8 @@ from PIL import Image
from paddlehub.module.module import serving, RunModule from paddlehub.module.module import serving, RunModule
from paddlehub.utils.utils import base64_to_cv2 from paddlehub.utils.utils import base64_to_cv2
import paddlehub.process.transforms as T import paddlehub.transforms.transforms as T
import paddlehub.process.functional as Func import paddlehub.transforms.functional as Func
class ImageServing(object): class ImageServing(object):
......
...@@ -9,7 +9,7 @@ import PIL ...@@ -9,7 +9,7 @@ import PIL
from PIL import Image, ImageEnhance from PIL import Image, ImageEnhance
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from paddlehub.process.functional import * from paddlehub.transforms.functional import *
matplotlib.use('Agg') matplotlib.use('Agg')
...@@ -27,6 +27,7 @@ class RandomDistort: ...@@ -27,6 +27,7 @@ class RandomDistort:
data(dict): Image info and label info. data(dict): Image info and label info.
""" """
def __init__(self, lower: float = 0.5, upper: float = 1.5): def __init__(self, lower: float = 0.5, upper: float = 1.5):
self.lower = lower self.lower = lower
self.upper = upper self.upper = upper
...@@ -70,6 +71,7 @@ class RandomExpand: ...@@ -70,6 +71,7 @@ class RandomExpand:
data(dict): Image info and label info. 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): def __init__(self, max_ratio: float = 4., fill: list = None, keep_ratio: bool = True, thresh: float = 0.5):
self.max_ratio = max_ratio self.max_ratio = max_ratio
...@@ -129,10 +131,8 @@ class RandomCrop: ...@@ -129,10 +131,8 @@ class RandomCrop:
data(dict): Image info and label info. data(dict): Image info and label info.
""" """
def __init__(self,
scales: list = [0.3, 1.0], def __init__(self, scales: list = [0.3, 1.0], max_ratio: float = 2.0, constraints: list = None,
max_ratio: float = 2.0,
constraints: list = None,
max_trial: int = 50): max_trial: int = 50):
self.scales = scales self.scales = scales
self.max_ratio = max_ratio self.max_ratio = max_ratio
...@@ -198,6 +198,7 @@ class RandomFlip: ...@@ -198,6 +198,7 @@ class RandomFlip:
img(np.ndarray): Distorted image. img(np.ndarray): Distorted image.
data(dict): Image info and label info. data(dict): Image info and label info.
""" """
def __init__(self, thresh: float = 0.5): def __init__(self, thresh: float = 0.5):
self.thresh = thresh self.thresh = thresh
...@@ -221,6 +222,7 @@ class Compose: ...@@ -221,6 +222,7 @@ class Compose:
img(np.ndarray): Preprocessed image. img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None. data(dict): Image info and label info, default is None.
""" """
def __init__(self, transforms: list): def __init__(self, transforms: list):
if not isinstance(transforms, list): if not isinstance(transforms, list):
raise TypeError('The transforms must be a list!') raise TypeError('The transforms must be a list!')
...@@ -263,6 +265,7 @@ class Resize: ...@@ -263,6 +265,7 @@ class Resize:
img(np.ndarray): Preprocessed image. img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None. data(dict): Image info and label info, default is None.
""" """
def __init__(self, target_size: int = 512, interp: str = 'RANDOM'): def __init__(self, target_size: int = 512, interp: str = 'RANDOM'):
self.interp_dict = { self.interp_dict = {
'NEAREST': cv2.INTER_NEAREST, 'NEAREST': cv2.INTER_NEAREST,
...@@ -309,6 +312,7 @@ class Normalize: ...@@ -309,6 +312,7 @@ class Normalize:
img(np.ndarray): Preprocessed image. img(np.ndarray): Preprocessed image.
data(dict): Image info and label info, default is None. 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]): def __init__(self, mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]):
self.mean = mean self.mean = mean
self.std = std self.std = std
...@@ -332,6 +336,7 @@ class Normalize: ...@@ -332,6 +336,7 @@ class Normalize:
class ShuffleBox: class ShuffleBox:
"""Shuffle detection information for corresponding input image.""" """Shuffle detection information for corresponding input image."""
def __call__(self, img, data): def __call__(self, img, data):
gt = np.concatenate([data['gt_boxes'], data['gt_labels'][:, np.newaxis], data['gt_scores'][:, np.newaxis]], gt = np.concatenate([data['gt_boxes'], data['gt_labels'][:, np.newaxis], data['gt_scores'][:, np.newaxis]],
axis=1) axis=1)
......
...@@ -29,7 +29,7 @@ from matplotlib import pyplot as plt ...@@ -29,7 +29,7 @@ from matplotlib import pyplot as plt
from matplotlib.figure import Figure from matplotlib.figure import Figure
from scipy.ndimage.filters import gaussian_filter from scipy.ndimage.filters import gaussian_filter
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from paddlehub.process.functional import * from paddlehub.transforms.functional import *
matplotlib.use('Agg') matplotlib.use('Agg')
...@@ -252,13 +252,8 @@ class RandomPaddingCrop: ...@@ -252,13 +252,8 @@ class RandomPaddingCrop:
pad_height = max(crop_height - img_height, 0) pad_height = max(crop_height - img_height, 0)
pad_width = max(crop_width - img_width, 0) pad_width = max(crop_width - img_width, 0)
if (pad_height > 0 or pad_width > 0): if (pad_height > 0 or pad_width > 0):
im = cv2.copyMakeBorder(im, im = cv2.copyMakeBorder(
0, im, 0, pad_height, 0, pad_width, cv2.BORDER_CONSTANT, value=self.im_padding_value)
pad_height,
0,
pad_width,
cv2.BORDER_CONSTANT,
value=self.im_padding_value)
if crop_height > 0 and crop_width > 0: if crop_height > 0 and crop_width > 0:
h_off = np.random.randint(img_height - crop_height + 1) h_off = np.random.randint(img_height - crop_height + 1)
...@@ -313,12 +308,13 @@ class RandomRotation: ...@@ -313,12 +308,13 @@ class RandomRotation:
r[0, 2] += (nw / 2) - cx r[0, 2] += (nw / 2) - cx
r[1, 2] += (nh / 2) - cy r[1, 2] += (nh / 2) - cy
dsize = (nw, nh) dsize = (nw, nh)
im = cv2.warpAffine(im, im = cv2.warpAffine(
r, im,
dsize=dsize, r,
flags=cv2.INTER_LINEAR, dsize=dsize,
borderMode=cv2.BORDER_CONSTANT, flags=cv2.INTER_LINEAR,
borderValue=self.im_padding_value) borderMode=cv2.BORDER_CONSTANT,
borderValue=self.im_padding_value)
return im return im
...@@ -425,6 +421,7 @@ class RGB2LAB: ...@@ -425,6 +421,7 @@ class RGB2LAB:
""" """
Convert color space from RGB to LAB. Convert color space from RGB to LAB.
""" """
def rgb2xyz(self, rgb: np.ndarray) -> np.ndarray: def rgb2xyz(self, rgb: np.ndarray) -> np.ndarray:
""" """
Convert color space from RGB to XYZ. Convert color space from RGB to XYZ.
...@@ -491,6 +488,7 @@ class LAB2RGB: ...@@ -491,6 +488,7 @@ class LAB2RGB:
""" """
Convert color space from LAB to RGB. Convert color space from LAB to RGB.
""" """
def __init__(self, mode: str = 'RGB2LAB'): def __init__(self, mode: str = 'RGB2LAB'):
self.mode = mode self.mode = mode
...@@ -568,6 +566,7 @@ class ColorPostprocess: ...@@ -568,6 +566,7 @@ class ColorPostprocess:
Return: Return:
img(np.ndarray): Image in range of 0-255. img(np.ndarray): Image in range of 0-255.
""" """
def __init__(self, type: type = np.uint8): def __init__(self, type: type = np.uint8):
self.type = type self.type = type
...@@ -588,6 +587,7 @@ class CenterCrop: ...@@ -588,6 +587,7 @@ class CenterCrop:
Return: Return:
img(np.ndarray): Croped image. img(np.ndarray): Croped image.
""" """
def __init__(self, crop_size: int): def __init__(self, crop_size: int):
self.crop_size = crop_size self.crop_size = crop_size
...@@ -608,6 +608,7 @@ class SetType: ...@@ -608,6 +608,7 @@ class SetType:
Return: Return:
img(np.ndarray): Transformed image. img(np.ndarray): Transformed image.
""" """
def __init__(self, datatype: type = 'float32'): def __init__(self, datatype: type = 'float32'):
self.type = datatype self.type = datatype
...@@ -623,6 +624,7 @@ class ResizeScaling: ...@@ -623,6 +624,7 @@ class ResizeScaling:
target(int): Target image size. target(int): Target image size.
interp(Callable): Interpolation method. interp(Callable): Interpolation method.
""" """
def __init__(self, target: int = 368, interp: Callable = cv2.INTER_CUBIC): def __init__(self, target: int = 368, interp: Callable = cv2.INTER_CUBIC):
self.target = target self.target = target
self.interp = interp self.interp = interp
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册