Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
d3f9375f
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看板
提交
d3f9375f
编写于
11月 04, 2021
作者:
C
chenjian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add see in the dark module
上级
8f403bac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
205 addition
and
0 deletion
+205
-0
modules/image/image_processing/seeinthedark/README.md
modules/image/image_processing/seeinthedark/README.md
+83
-0
modules/image/image_processing/seeinthedark/module.py
modules/image/image_processing/seeinthedark/module.py
+120
-0
modules/image/image_processing/seeinthedark/requirements.txt
modules/image/image_processing/seeinthedark/requirements.txt
+2
-0
未找到文件。
modules/image/image_processing/seeinthedark/README.md
0 → 100644
浏览文件 @
d3f9375f
# seeinthedark
|模型名称|seeinthedark|
| :--- | :---: |
|类别|图像 - 暗光增强|
|网络|ConvNet|
|数据集|SID dataset|
|是否支持Fine-tuning|否|
|模型大小|120MB|
|最新更新日期|2021-11-02|
|数据指标|-|
## 一、模型基本信息
-
### 模型介绍
-
通过大量暗光条件下短曝光和长曝光组成的图像对,以RAW图像为输入,RGB图像为参照进行训练,该模型实现端到端直接将暗光下的RAW图像处理得到可见的RGB图像。
-
更多详情参考:
[
Learning to See in the Dark
](
http://cchen156.github.io/paper/18CVPR_SID.pdf
)
## 二、安装
-
### 1、环境依赖
-
rawpy
-
pillow
-
### 2、安装
-
```shell
$ hub install seeinthedark
```
-
如您安装时遇到问题,可参考:
[
零基础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
)
-
在windows下安装,由于paddledet package会依赖cython-bbox以及pycocotools, 这两个包需要windows用户提前装好,可参考
[
cython-bbox安装
](
https://blog.csdn.net/qq_24739717/article/details/105588729
)
和
[
pycocotools安装
](
https://github.com/PaddlePaddle/PaddleX/blob/release/1.3/docs/install.md#pycocotools安装问题
)
## 三、模型API预测
-
### 1、命令行预测
-
```shell
# Read from a raw(Sony, .ARW) file
$ hub run seeinthedark --input_path "/PATH/TO/IMAGE"
```
-
通过命令行方式实现暗光增强模型的调用,更多请见
[
PaddleHub命令行指令
](
../../../../docs/docs_ch/tutorial/cmd_usage.rst
)
-
### 2、代码示例
-
```python
import paddlehub as hub
denoiser = hub.Module(name="seeinthedark")
input_path = "/PATH/TO/IMAGE"
# Read from a raw file
denoiser.denoising(input_path, output_path='./denoising_result.png', use_gpu=True)
```
-
### 3、API
-
```python
def denoising(input_path, output_path='./denoising_result.png', use_gpu=False)
```
-
暗光增强API,完成对暗光RAW图像的降噪并处理生成RGB图像。
- **参数**
- input\_path (str): 暗光图像文件的路径,Sony的RAW格式; <br/>
- output\_path (str): 结果保存的路径, 需要指定输出文件名; <br/>
- use\_gpu (bool): 是否使用 GPU;<br/>
## 四、更新历史
*
1.0.0
初始发布
-
```shell
$ hub install seeinthedark==1.0.0
```
modules/image/image_processing/seeinthedark/module.py
0 → 100644
浏览文件 @
d3f9375f
# Copyright (c) 2021 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.
import
os
import
argparse
import
paddle
import
paddlehub
as
hub
from
paddlehub.module.module
import
moduleinfo
,
runnable
import
numpy
as
np
import
rawpy
from
PIL
import
Image
def
pack_raw
(
raw
):
# pack Bayer image to 4 channels
im
=
raw
.
raw_image_visible
.
astype
(
np
.
float32
)
im
=
np
.
maximum
(
im
-
512
,
0
)
/
(
16383
-
512
)
# subtract the black level
im
=
np
.
expand_dims
(
im
,
axis
=
2
)
img_shape
=
im
.
shape
H
=
img_shape
[
0
]
W
=
img_shape
[
1
]
out
=
np
.
concatenate
((
im
[
0
:
H
:
2
,
0
:
W
:
2
,
:],
im
[
0
:
H
:
2
,
1
:
W
:
2
,
:],
im
[
1
:
H
:
2
,
1
:
W
:
2
,
:],
im
[
1
:
H
:
2
,
0
:
W
:
2
,
:]),
axis
=
2
)
return
out
@
moduleinfo
(
name
=
"seeinthedark"
,
type
=
"CV/denoising"
,
author
=
"paddlepaddle"
,
author_email
=
""
,
summary
=
""
,
version
=
"1.0.0"
)
class
LearningToSeeInDark
:
def
__init__
(
self
):
self
.
pretrained_model
=
os
.
path
.
join
(
self
.
directory
,
"pd_model/inference_model"
)
def
denoising
(
self
,
input_path
,
output_path
=
'./denoising_result.png'
,
use_gpu
=
False
):
'''
Denoise a raw image in the low-light scene.
input_path: the raw image path
output_path: the path to save the results
use_gpu: if True, use gpu to perform the computation, otherwise cpu.
'''
paddle
.
enable_static
()
if
use_gpu
==
False
:
exe
=
paddle
.
static
.
Executor
(
paddle
.
CPUPlace
())
else
:
exe
=
paddle
.
static
.
Executor
(
paddle
.
CUDAPlace
(
0
))
[
prog
,
inputs
,
outputs
]
=
paddle
.
static
.
load_inference_model
(
path_prefix
=
self
.
pretrained_model
,
executor
=
exe
,
model_filename
=
"model.pdmodel"
,
params_filename
=
"model.pdiparams"
)
raw
=
rawpy
.
imread
(
input_path
)
input_full
=
np
.
expand_dims
(
pack_raw
(
raw
),
axis
=
0
)
*
300
px
=
input_full
.
shape
[
1
]
//
512
py
=
input_full
.
shape
[
2
]
//
512
rx
,
ry
=
px
*
512
,
py
*
512
input_full
=
input_full
[:,
:
rx
,
:
ry
,
:]
output
=
np
.
random
.
randn
(
rx
*
2
,
ry
*
2
,
3
)
input_full
=
np
.
minimum
(
input_full
,
1.0
)
for
i
in
range
(
px
):
for
j
in
range
(
py
):
input_patch
=
input_full
[:,
i
*
512
:
i
*
512
+
512
,
j
*
512
:
j
*
512
+
512
,
:]
result
=
exe
.
run
(
prog
,
feed
=
{
inputs
[
0
]:
input_patch
},
fetch_list
=
outputs
)
output
[
i
*
512
*
2
:
i
*
512
*
2
+
512
*
2
,
j
*
512
*
2
:
j
*
512
*
2
+
512
*
2
,
:]
=
result
[
0
][
0
]
output
=
np
.
minimum
(
np
.
maximum
(
output
,
0
),
1
)
print
(
'Denoising Over.'
)
try
:
Image
.
fromarray
(
np
.
uint8
(
output
*
255
)).
save
(
os
.
path
.
join
(
output_path
))
print
(
'Image saved in {}'
.
format
(
output_path
))
except
:
print
(
'Save image failed. Please check the output_path, should
\
be image format ext, e.g. png. current output path {}'
.
format
(
output_path
))
@
runnable
def
run_cmd
(
self
,
argvs
:
list
):
"""
Run as a command.
"""
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
"Run the {} module."
.
format
(
self
.
name
),
prog
=
'hub run {}'
.
format
(
self
.
name
),
usage
=
'%(prog)s'
,
add_help
=
True
)
self
.
arg_input_group
=
self
.
parser
.
add_argument_group
(
title
=
"Input options"
,
description
=
"Input data. Required"
)
self
.
arg_config_group
=
self
.
parser
.
add_argument_group
(
title
=
"Config options"
,
description
=
"Run configuration for controlling module behavior, not required."
)
self
.
add_module_config_arg
()
self
.
add_module_input_arg
()
self
.
args
=
self
.
parser
.
parse_args
(
argvs
)
self
.
denoising
(
input_path
=
self
.
args
.
input_path
,
output_path
=
self
.
args
.
output_path
,
use_gpu
=
self
.
args
.
use_gpu
)
def
add_module_config_arg
(
self
):
"""
Add the command config options.
"""
self
.
arg_config_group
.
add_argument
(
'--use_gpu'
,
action
=
'store_true'
,
help
=
"use GPU or not"
)
self
.
arg_config_group
.
add_argument
(
'--output_path'
,
type
=
str
,
default
=
'denoising_result.png'
,
help
=
'output path for saving result.'
)
def
add_module_input_arg
(
self
):
"""
Add the command input options.
"""
self
.
arg_input_group
.
add_argument
(
'--input_path'
,
type
=
str
,
help
=
"path to input raw image, should be raw file captured by camera."
)
modules/image/image_processing/seeinthedark/requirements.txt
0 → 100644
浏览文件 @
d3f9375f
rawpy
pillow
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录