提交 e93c01e4 编写于 作者: W wuzewu

Rename paddlehub.process -> paddlehub.transforms

上级 1ed226af
......@@ -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')
import paddle
import paddlehub as hub
import paddlehub.process.transforms as T
import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import Canvas
......
import paddle
import paddlehub as hub
import paddlehub.process.transforms as T
import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import Flowers
......
import paddle
import paddlehub as hub
import paddlehub.process.transforms as T
import paddlehub.transforms.transforms as T
from paddlehub.finetune.trainer import Trainer
from paddlehub.datasets import MiniCOCO
......
......@@ -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.process.transforms as T
import paddlehub.transforms.transforms as T
from paddlehub.module.cv_module import ImageColorizeModule
from user_guided_colorization.data_feed import ColorizePreprocess
......
......@@ -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.process.transforms as T
from paddlehub.transforms.module import moduleinfo
import paddlehub.transforms.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__()
......
......@@ -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.process.transforms as T
import paddlehub.transforms.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
......
......@@ -7,12 +7,13 @@ import paddle.nn.functional as F
from paddlehub.env import MODULE_HOME
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
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()
......
......@@ -18,7 +18,7 @@ import os
import numpy as np
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 typing import Callable
from paddlehub.utils.download import download_data
......
......@@ -17,7 +17,7 @@ import os
from typing import Callable
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.utils.download import download_data
......
......@@ -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.process.transforms as T
import paddlehub.process.functional as Func
import paddlehub.transforms.transforms as T
import paddlehub.transforms.functional as Func
class ImageServing(object):
......
......@@ -9,7 +9,7 @@ import PIL
from PIL import Image, ImageEnhance
from matplotlib import pyplot as plt
from paddlehub.process.functional import *
from paddlehub.transforms.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)
......
......@@ -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.process.functional import *
from paddlehub.transforms.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.
先完成此消息的编辑!
想要评论请 注册