Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
4d67dba0
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4d67dba0
编写于
1月 11, 2019
作者:
工药叉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bug
上级
ce96b3a9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
18 addition
and
17 deletion
+18
-17
fluid/SRCNN/README.md
fluid/SRCNN/README.md
+1
-1
fluid/SRCNN/infer.py
fluid/SRCNN/infer.py
+11
-10
fluid/SRCNN/train.py
fluid/SRCNN/train.py
+4
-4
fluid/SRCNN/utils.py
fluid/SRCNN/utils.py
+2
-2
未找到文件。
fluid/SRCNN/README.md
浏览文件 @
4d67dba0
...
...
@@ -78,7 +78,7 @@ mode: 指定模型结构。如果为“base”,使用论文baseline模型结
### 预测
执行以下命令得到模型的预测结果。
```
python infer.py --checkpoint_path="./chkpnt/" --
use_gpu=True --
image_path="data/val_dataset/set5/baby_GT.bmp"
python infer.py --checkpoint_path="./chkpnt/" --image_path="data/val_dataset/set5/baby_GT.bmp"
```
需要通过选项
`--checkpoint_path`
指定模型文件。并使用
`--image_path`
指定要进行预测的图片。
...
...
fluid/SRCNN/infer.py
浏览文件 @
4d67dba0
...
...
@@ -18,7 +18,7 @@ add_arg = functools.partial(add_arguments, argparser=parser)
add_arg
(
'checkpoint_path'
,
str
,
'model'
,
"Checkpoint save path."
)
add_arg
(
'image_path'
,
str
,
'data/val_dataset/set5/baby_GT.bmp'
,
"Img data path."
)
add_arg
(
'show_img'
,
bool
,
Tru
e
,
"show img or not"
)
add_arg
(
'show_img'
,
bool
,
Fals
e
,
"show img or not"
)
add_arg
(
'only_reconstruct'
,
bool
,
False
,
"If True, input image is seemed as subsampled image"
)
add_arg
(
'scale_factor'
,
int
,
3
,
"scale factor"
)
...
...
@@ -29,8 +29,8 @@ def reconstruct_img(args):
img_test
=
cv2
.
imread
(
args
.
image_path
)
yuv_test
=
cv2
.
cvtColor
(
img_test
,
cv2
.
COLOR_BGR2YCrCb
)
img_h
,
img_w
,
img_c
=
img_test
.
shape
cv2
.
imshow
(
'raw image'
,
img_test
)
if
args
.
show_img
:
cv2
.
imshow
(
'raw image'
,
img_test
)
if
args
.
only_reconstruct
==
False
:
# blur image and cubic interpolation
...
...
@@ -55,16 +55,17 @@ def reconstruct_img(args):
result_img
[
result_img
>
255
]
=
255
gap_y
=
int
((
img_y
.
shape
[
0
]
-
result_img
.
shape
[
2
])
/
2
)
gap_x
=
int
((
img_y
.
shape
[
1
]
-
result_img
.
shape
[
3
])
/
2
)
cv2
.
imshow
(
'input_channel y'
,
img_y
)
if
args
.
show_img
:
cv2
.
imshow
(
'input_channel y'
,
img_y
)
cv2
.
imwrite
(
os
.
path
.
join
(
os
.
path
.
split
(
args
.
image_path
)[
0
],
'beforeSR_'
+
os
.
path
.
split
(
args
.
image_path
)[
1
]),
img_y
)
img_y
[
gap_y
:
gap_y
+
result_img
.
shape
[
2
],
gap_x
:
gap_x
+
result_img
.
shape
[
3
]]
=
result_img
if
args
.
show_img
:
cv2
.
imshow
(
'output_channel y'
,
img_y
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'output_channel y'
,
img_y
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
cv2
.
destroyAllWindows
()
cv2
.
imwrite
(
os
.
path
.
join
(
os
.
path
.
split
(
args
.
image_path
)[
0
],
'afterSR_'
+
os
.
path
.
split
(
args
.
image_path
)[
1
]),
img_y
)
return
img_y
if
__name__
==
"__main__"
:
...
...
fluid/SRCNN/train.py
浏览文件 @
4d67dba0
...
...
@@ -37,17 +37,17 @@ N2=32
def
net
(
X
,
Y
,
model_struct
):
# construct net
conv1
=
fluid
.
layers
.
nn
.
conv2d
(
X
,
model_struct
.
n1
,
model_struct
.
f1
,
act
=
'relu'
,
name
=
'conv1'
,
conv1
=
fluid
.
layers
.
conv2d
(
X
,
model_struct
.
n1
,
model_struct
.
f1
,
act
=
'relu'
,
name
=
'conv1'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
NormalInitializer
(
scale
=
0.001
),
name
=
'conv1_w'
),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
ConstantInitializer
(
value
=
0.
),
name
=
'conv1_b'
))
conv2
=
fluid
.
layers
.
nn
.
conv2d
(
conv1
,
model_struct
.
n2
,
model_struct
.
f2
,
act
=
'relu'
,
name
=
'conv2'
,
conv2
=
fluid
.
layers
.
conv2d
(
conv1
,
model_struct
.
n2
,
model_struct
.
f2
,
act
=
'relu'
,
name
=
'conv2'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
NormalInitializer
(
scale
=
0.001
),
name
=
'conv2_w'
),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
ConstantInitializer
(
value
=
0.
),
name
=
'conv2_b'
))
pred
=
fluid
.
layers
.
nn
.
conv2d
(
conv2
,
1
,
model_struct
.
f3
,
name
=
'pred'
,
pred
=
fluid
.
layers
.
conv2d
(
conv2
,
1
,
model_struct
.
f3
,
name
=
'pred'
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
NormalInitializer
(
scale
=
0.001
),
name
=
'pred_w'
),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
ConstantInitializer
(
value
=
0.
),
...
...
@@ -94,7 +94,7 @@ def train(args):
fluid
.
framework
.
default_main_program
(),
feed
=
feeder
.
feed
(
data
),
fetch_list
=
[
y_loss
])
if
batch_id
==
0
or
backprops_cnt
%
100
==
0
:
if
batch_id
==
0
:
fluid
.
io
.
save_inference_model
(
args
.
checkpoint_path
,
[
'image'
],
[
y_predict
],
exe
)
val_loss
,
val_psnr
=
validation
()
print
(
"%i
\t
Epoch: %d
\t
Cur Cost : %f
\t
Val Cost: %f
\t
PSNR :%f"
%
(
backprops_cnt
,
epoch
,
np
.
array
(
loss
[
0
])[
0
],
val_loss
,
val_psnr
))
...
...
fluid/SRCNN/utils.py
浏览文件 @
4d67dba0
...
...
@@ -50,8 +50,8 @@ def read_data(data_path, batch_size, ext, scale_factor, bia_size):
img_blur
=
cv2
.
GaussianBlur
(
img_patch
,
(
5
,
5
),
0
)
img_sumsample
=
cv2
.
resize
(
img_blur
,
(
int
(
33
/
scale_factor
),
int
(
33
/
scale_factor
)))
img_input
=
cv2
.
resize
(
img_blur
,
(
33
,
33
),
interpolation
=
cv2
.
INTER_CUBIC
)
img_inputs
.
append
(
img_input
)
img_gths
.
append
(
img_gth
)
img_inputs
.
append
(
[
img_input
]
)
img_gths
.
append
(
[
img_gth
]
)
count_bt
+=
1
if
count_bt
%
batch_size
==
0
:
yield
[[
np
.
array
(
img_inputs
),
np
.
array
(
img_gths
)]]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录