Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
827270b7
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看板
提交
827270b7
编写于
3月 14, 2022
作者:
C
chenjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce
上级
4b4d8cf8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
8 addition
and
49 deletion
+8
-49
modules/image/image_processing/enlightengan/enlighten_inference/__init__.py
...e_processing/enlightengan/enlighten_inference/__init__.py
+0
-37
modules/image/image_processing/enlightengan/enlighten_inference/pd_model/x2paddle_code.py
...nlightengan/enlighten_inference/pd_model/x2paddle_code.py
+0
-1
modules/image/image_processing/enlightengan/module.py
modules/image/image_processing/enlightengan/module.py
+8
-9
modules/image/image_processing/enlightengan/requirements.txt
modules/image/image_processing/enlightengan/requirements.txt
+0
-2
未找到文件。
modules/image/image_processing/enlightengan/enlighten_inference/__init__.py
已删除
100755 → 0
浏览文件 @
4b4d8cf8
import
os
from
typing
import
Union
import
numpy
as
np
from
onnxruntime
import
InferenceSession
def
get_relative_path
(
root
,
*
args
):
return
os
.
path
.
join
(
os
.
path
.
dirname
(
root
),
*
args
)
class
EnlightenOnnxModel
:
def
__init__
(
self
,
model
:
Union
[
bytes
,
str
,
None
]
=
None
):
self
.
graph
=
InferenceSession
(
model
or
get_relative_path
(
__file__
,
'enlighten.onnx'
))
def
__repr__
(
self
):
return
'<EnlightenGAN OnnxModel> {}'
.
format
(
id
(
self
))
def
_pad
(
self
,
img
):
h
,
w
,
_
=
img
.
shape
block_size
=
16
min_height
=
(
h
//
block_size
+
1
)
*
block_size
min_width
=
(
w
//
block_size
+
1
)
*
block_size
img
=
np
.
pad
(
img
,
((
0
,
min_height
-
h
),
(
0
,
min_width
-
w
),
(
0
,
0
)),
mode
=
'constant'
,
constant_values
=
0
)
return
img
,
(
h
,
w
)
def
_preprocess
(
self
,
img
):
if
len
(
img
.
shape
)
!=
3
:
raise
ValueError
(
'Incorrect shape: expected 3, got {}'
.
format
(
img
.
shape
))
return
np
.
expand_dims
(
np
.
transpose
(
img
,
(
2
,
0
,
1
)).
astype
(
np
.
float32
)
/
255.
,
0
)
def
predict
(
self
,
img
):
padded
,
(
h
,
w
)
=
self
.
_pad
(
img
)
image_numpy
,
=
self
.
graph
.
run
([
'output'
],
{
'input'
:
self
.
_preprocess
(
padded
)})
image_numpy
=
(
np
.
transpose
(
image_numpy
[
0
],
(
1
,
2
,
0
))
+
1
)
/
2.0
*
255.0
image_numpy
=
np
.
clip
(
image_numpy
,
0
,
255
)
return
image_numpy
.
astype
(
'uint8'
)[:
h
,
:
w
,
:]
modules/image/image_processing/enlightengan/enlighten_inference/pd_model/x2paddle_code.py
浏览文件 @
827270b7
import
paddle
import
math
from
x2paddle.op_mapper.onnx2paddle
import
onnx_custom_layer
as
x2paddle_nn
class
ONNXModel
(
paddle
.
nn
.
Layer
):
...
...
modules/image/image_processing/enlightengan/module.py
浏览文件 @
827270b7
...
...
@@ -21,7 +21,6 @@ from paddlehub.module.module import moduleinfo, runnable, serving
import
numpy
as
np
import
cv2
from
.enlighten_inference
import
EnlightenOnnxModel
from
.enlighten_inference.pd_model.x2paddle_code
import
ONNXModel
from
.util
import
base64_to_cv2
...
...
@@ -36,19 +35,19 @@ class EnlightenGAN:
self
.
model
.
set_dict
(
params
,
use_structured_name
=
True
)
def
enlightening
(
self
,
images
=
None
,
paths
=
None
,
output_dir
=
'./enlightening_result/'
,
use_gpu
=
False
,
visualization
=
True
):
images
:
list
=
None
,
paths
:
list
=
None
,
output_dir
:
str
=
'./enlightening_result/'
,
use_gpu
:
bool
=
False
,
visualization
:
bool
=
True
):
'''
enlighten images in the low-light scene.
images (list[numpy.ndarray]): data of images, shape of each is [H, W, C], color space must be BGR(read by cv2).
paths (list[str]): paths to images
output_dir: the dir to save the results
use_gpu: if True, use gpu to perform the computation, otherwise cpu.
visualization: if True, save results in output_dir.
output_dir
(str)
: the dir to save the results
use_gpu
(bool)
: if True, use gpu to perform the computation, otherwise cpu.
visualization
(bool)
: if True, save results in output_dir.
'''
results
=
[]
paddle
.
disable_static
()
...
...
modules/image/image_processing/enlightengan/requirements.txt
已删除
100644 → 0
浏览文件 @
4b4d8cf8
onnxruntime
x2paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录