diff --git a/modules/image/Image_editing/colorization/deoldify/README.md b/modules/image/Image_editing/colorization/deoldify/README.md index c4303720a52c02215250d23158798053659014f1..30221d1106839b181ff2de89077f59c35ec09afc 100644 --- a/modules/image/Image_editing/colorization/deoldify/README.md +++ b/modules/image/Image_editing/colorization/deoldify/README.md @@ -1,7 +1,7 @@ # deoldify |模型名称|deoldify| -| :--- | :---: | +| :--- | :---: | |类别|图像-图像编辑| |网络|NoGAN| |数据集|ILSVRC 2012| @@ -14,7 +14,7 @@ ## 一、模型基本信息 - ### 应用效果展示 - + - 样例结果示例(左为原图,右为效果图):
@@ -45,7 +45,7 @@
- ```shell
$ hub install deoldify
```
-
+
- 如您安装时遇到问题,可参考:[零基础windows安装](../../../../docs/docs_ch/get_start/windows_quickstart.md)
| [零基础Linux安装](../../../../docs/docs_ch/get_start/linux_quickstart.md) | [零基础MacOS安装](../../../../docs/docs_ch/get_start/mac_quickstart.md)
@@ -59,7 +59,9 @@
import paddlehub as hub
model = hub.Module(name='deoldify')
- model.predict('/PATH/TO/IMAGE/OR/VIDEO')
+ model.predict('/PATH/TO/IMAGE')
+
+ # model.predict('/PATH/TO/VIDEO')
```
- ### 2、API
@@ -170,3 +172,11 @@
* 1.0.1
适配paddlehub2.0版本
+
+* 1.1.0
+
+ 移除 Fluid API
+
+ ```shell
+ $ hub install deoldify == 1.1.0
+ ```
diff --git a/modules/image/Image_editing/colorization/deoldify/README_en.md b/modules/image/Image_editing/colorization/deoldify/README_en.md
index cbfcd6078a00e7dbf81b07c5a527e494dcad6093..c08d1a68e3a20c6eca510ddc2222af93ac8648cc 100644
--- a/modules/image/Image_editing/colorization/deoldify/README_en.md
+++ b/modules/image/Image_editing/colorization/deoldify/README_en.md
@@ -1,7 +1,7 @@
# deoldify
| Module Name |deoldify|
-| :--- | :---: |
+| :--- | :---: |
|Category|Image editing|
|Network |NoGAN|
|Dataset|ILSVRC 2012|
@@ -11,10 +11,10 @@
|Latest update date |2021-04-13|
-## I. Basic Information
+## I. Basic Information
- ### Application Effect Display
-
+
- Sample results:
@@ -45,7 +45,7 @@
- ```shell
$ hub install deoldify
```
-
+
- In case of any problems during installation, please refer to:[Windows_Quickstart](../../../../docs/docs_en/get_start/windows_quickstart.md)
| [Linux_Quickstart](../../../../docs/docs_en/get_start/linux_quickstart.md) | [Mac_Quickstart](../../../../docs/docs_en/get_start/mac_quickstart.md)
@@ -58,7 +58,9 @@
import paddlehub as hub
model = hub.Module(name='deoldify')
- model.predict('/PATH/TO/IMAGE/OR/VIDEO')
+ model.predict('/PATH/TO/IMAGE')
+
+ # model.predict('/PATH/TO/VIDEO')
```
- ### 2、API
@@ -169,3 +171,11 @@
- 1.0.1
Adapt to paddlehub2.0
+
+* 1.1.0
+
+ Remove Fluid API
+
+ ```shell
+ $ hub install deoldify == 1.1.0
+ ```
diff --git a/modules/image/Image_editing/colorization/deoldify/base_module.py b/modules/image/Image_editing/colorization/deoldify/base_module.py
index 3c36d2d873c0f7f722cafdf0907a640135d723cf..9ab0bd60d8f4019fa4203507ae3f8b4ebd620900 100644
--- a/modules/image/Image_editing/colorization/deoldify/base_module.py
+++ b/modules/image/Image_editing/colorization/deoldify/base_module.py
@@ -1,10 +1,10 @@
-import paddle
import numpy as np
+import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from paddle.vision.models import resnet101
-import deoldify.utils as U
+from . import utils as U
class SequentialEx(nn.Layer):
@@ -39,6 +39,7 @@ class SequentialEx(nn.Layer):
class Deoldify(SequentialEx):
+
def __init__(self,
encoder,
n_classes,
@@ -76,17 +77,16 @@ class Deoldify(SequentialEx):
n_out = nf if not_final else nf // 2
- unet_block = UnetBlockWide(
- up_in_c,
- x_in_c,
- n_out,
- self.sfs[i],
- final_div=not_final,
- blur=blur,
- self_attention=sa,
- norm_type=norm_type,
- extra_bn=extra_bn,
- **kwargs)
+ unet_block = UnetBlockWide(up_in_c,
+ x_in_c,
+ n_out,
+ self.sfs[i],
+ final_div=not_final,
+ blur=blur,
+ self_attention=sa,
+ norm_type=norm_type,
+ extra_bn=extra_bn,
+ **kwargs)
unet_block.eval()
layers.append(unet_block)
x = unet_block(x)
@@ -288,7 +288,7 @@ class CustomPixelShuffle_ICNR(nn.Layer):
self.shuf = PixelShuffle(scale)
self.pad = ReplicationPad2d([1, 0, 1, 0])
- self.blur = paddle.nn.AvgPool2D(2, stride=1)
+ self.blur = nn.AvgPool2D(2, stride=1)
self.relu = nn.LeakyReLU(leaky) if leaky is not None else nn.ReLU() # relu(True, leaky=leaky)
def forward(self, x):
@@ -315,9 +315,8 @@ def res_block(nf, dense: bool = False, norm_type='Batch', bottle: bool = False,
norm2 = norm_type
if not dense and (norm_type == 'Batch'): norm2 = 'BatchZero'
nf_inner = nf // 2 if bottle else nf
- return SequentialEx(
- conv_layer(nf, nf_inner, norm_type=norm_type, **conv_kwargs),
- conv_layer(nf_inner, nf, norm_type=norm2, **conv_kwargs), MergeLayer(dense))
+ return SequentialEx(conv_layer(nf, nf_inner, norm_type=norm_type, **conv_kwargs),
+ conv_layer(nf_inner, nf, norm_type=norm2, **conv_kwargs), MergeLayer(dense))
class SigmoidRange(nn.Layer):
@@ -337,6 +336,7 @@ def sigmoid_range(x, low, high):
class PixelShuffle(nn.Layer):
+
def __init__(self, upscale_factor):
super(PixelShuffle, self).__init__()
self.upscale_factor = upscale_factor
@@ -346,6 +346,7 @@ class PixelShuffle(nn.Layer):
class ReplicationPad2d(nn.Layer):
+
def __init__(self, size):
super(ReplicationPad2d, self).__init__()
self.size = size
diff --git a/modules/image/Image_editing/colorization/deoldify/module.py b/modules/image/Image_editing/colorization/deoldify/module.py
index 1cbe28f133892cf98a47a8e86baf2efa41613592..bcf896f499562c01d44bbb363202ce72a0e56aa3 100644
--- a/modules/image/Image_editing/colorization/deoldify/module.py
+++ b/modules/image/Image_editing/colorization/deoldify/module.py
@@ -12,32 +12,32 @@
# 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.
-
-import os
import glob
+import os
import cv2
+import numpy as np
import paddle
import paddle.nn as nn
-import numpy as np
from PIL import Image
from tqdm import tqdm
-import deoldify.utils as U
-from paddlehub.module.module import moduleinfo, serving, Module
-from deoldify.base_module import build_model
-
-
-@moduleinfo(
- name="deoldify",
- type="CV/image_editing",
- author="paddlepaddle",
- author_email="",
- summary="Deoldify is a colorizaton model",
- version="1.0.0")
-class DeOldifyPredictor(Module):
- def _initialize(self, render_factor: int = 32, output_path: int = 'result', load_checkpoint: str = None):
- #super(DeOldifyPredictor, self).__init__()
+from . import utils as U
+from .base_module import build_model
+from paddlehub.module.module import moduleinfo
+from paddlehub.module.module import serving
+
+
+@moduleinfo(name="deoldify",
+ type="CV/image_editing",
+ author="paddlepaddle",
+ author_email="",
+ summary="Deoldify is a colorizaton model",
+ version="1.1.0")
+class DeOldifyPredictor(nn.Layer):
+
+ def __init__(self, render_factor: int = 32, output_path: int = 'output', load_checkpoint: str = None):
+ super(DeOldifyPredictor, self).__init__()
self.model = build_model()
self.render_factor = render_factor
self.output = os.path.join(output_path, 'DeOldify')
@@ -50,6 +50,8 @@ class DeOldifyPredictor(Module):
else:
checkpoint = os.path.join(self.directory, 'DeOldify_stable.pdparams')
+ if not os.path.exists(checkpoint):
+ os.system('wget https://paddlegan.bj.bcebos.com/applications/DeOldify_stable.pdparams -O ' + checkpoint)
state_dict = paddle.load(checkpoint)
self.model.load_dict(state_dict)
print("load pretrained checkpoint success")
@@ -140,8 +142,6 @@ class DeOldifyPredictor(Module):
return frame_pattern_combined, vid_out_path
def predict(self, input):
- if not os.path.exists(self.output):
- os.makedirs(self.output)
if not U.is_image(input):
return self.run_video(input)
diff --git a/modules/image/Image_editing/colorization/deoldify/resnet.py b/modules/image/Image_editing/colorization/deoldify/resnet.py
deleted file mode 100644
index 46196c6bfa031e1a94c66b6f848157e3c34f0911..0000000000000000000000000000000000000000
--- a/modules/image/Image_editing/colorization/deoldify/resnet.py
+++ /dev/null
@@ -1,332 +0,0 @@
-# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
-#
-# 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.
-
-from __future__ import division
-from __future__ import print_function
-
-import math
-import paddle.fluid as fluid
-
-from paddle.fluid.dygraph.nn import Conv2D, Pool2D, BatchNorm, Linear
-from paddle.fluid.dygraph.container import Sequential
-
-from paddle.utils.download import get_weights_path_from_url
-
-__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152']
-
-model_urls = {
- 'resnet18': ('https://paddle-hapi.bj.bcebos.com/models/resnet18.pdparams', '0ba53eea9bc970962d0ef96f7b94057e'),
- 'resnet34': ('https://paddle-hapi.bj.bcebos.com/models/resnet34.pdparams', '46bc9f7c3dd2e55b7866285bee91eff3'),
- 'resnet50': ('https://paddle-hapi.bj.bcebos.com/models/resnet50.pdparams', '5ce890a9ad386df17cf7fe2313dca0a1'),
- 'resnet101': ('https://paddle-hapi.bj.bcebos.com/models/resnet101.pdparams', 'fb07a451df331e4b0bb861ed97c3a9b9'),
- 'resnet152': ('https://paddle-hapi.bj.bcebos.com/models/resnet152.pdparams', 'f9c700f26d3644bb76ad2226ed5f5713'),
-}
-
-
-class ConvBNLayer(fluid.dygraph.Layer):
- def __init__(self, num_channels, num_filters, filter_size, stride=1, groups=1, act=None):
- super(ConvBNLayer, self).__init__()
-
- self._conv = Conv2D(
- num_channels=num_channels,
- num_filters=num_filters,
- filter_size=filter_size,
- stride=stride,
- padding=(filter_size - 1) // 2,
- groups=groups,
- act=None,
- bias_attr=False)
-
- self._batch_norm = BatchNorm(num_filters, act=act)
-
- def forward(self, inputs):
- x = self._conv(inputs)
- x = self._batch_norm(x)
-
- return x
-
-
-class BasicBlock(fluid.dygraph.Layer):
- """residual block of resnet18 and resnet34
- """
- expansion = 1
-
- def __init__(self, num_channels, num_filters, stride, shortcut=True):
- super(BasicBlock, self).__init__()
-
- self.conv0 = ConvBNLayer(num_channels=num_channels, num_filters=num_filters, filter_size=3, act='relu')
- self.conv1 = ConvBNLayer(
- num_channels=num_filters, num_filters=num_filters, filter_size=3, stride=stride, act='relu')
-
- if not shortcut:
- self.short = ConvBNLayer(num_channels=num_channels, num_filters=num_filters, filter_size=1, stride=stride)
-
- self.shortcut = shortcut
-
- def forward(self, inputs):
- y = self.conv0(inputs)
- conv1 = self.conv1(y)
-
- if self.shortcut:
- short = inputs
- else:
- short = self.short(inputs)
-
- y = short + conv1
-
- return fluid.layers.relu(y)
-
-
-class BottleneckBlock(fluid.dygraph.Layer):
- """residual block of resnet50, resnet101 amd resnet152
- """
-
- expansion = 4
-
- def __init__(self, num_channels, num_filters, stride, shortcut=True):
- super(BottleneckBlock, self).__init__()
-
- self.conv0 = ConvBNLayer(num_channels=num_channels, num_filters=num_filters, filter_size=1, act='relu')
- self.conv1 = ConvBNLayer(
- num_channels=num_filters, num_filters=num_filters, filter_size=3, stride=stride, act='relu')
- self.conv2 = ConvBNLayer(
- num_channels=num_filters, num_filters=num_filters * self.expansion, filter_size=1, act=None)
-
- if not shortcut:
- self.short = ConvBNLayer(
- num_channels=num_channels, num_filters=num_filters * self.expansion, filter_size=1, stride=stride)
-
- self.shortcut = shortcut
-
- self._num_channels_out = num_filters * self.expansion
-
- def forward(self, inputs):
- x = self.conv0(inputs)
- conv1 = self.conv1(x)
- conv2 = self.conv2(conv1)
-
- if self.shortcut:
- short = inputs
- else:
- short = self.short(inputs)
-
- x = fluid.layers.elementwise_add(x=short, y=conv2)
-
- return fluid.layers.relu(x)
-
-
-class ResNet(fluid.dygraph.Layer):
- """ResNet model from
- `"Deep Residual Learning for Image Recognition"