Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleGAN
提交
1744b3a6
P
PaddleGAN
项目概览
PaddlePaddle
/
PaddleGAN
1 年多 前同步成功
通知
97
Star
7254
Fork
1210
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleGAN
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1744b3a6
编写于
10月 12, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add run image
上级
30159cf1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
21 deletion
+58
-21
ppgan/apps/base_predictor.py
ppgan/apps/base_predictor.py
+8
-6
ppgan/apps/deoldify_predictor.py
ppgan/apps/deoldify_predictor.py
+25
-7
ppgan/apps/realsr_predictor.py
ppgan/apps/realsr_predictor.py
+25
-8
未找到文件。
ppgan/apps/base_predictor.py
浏览文件 @
1744b3a6
...
...
@@ -13,6 +13,7 @@
#limitations under the License.
import
os
import
cv2
import
paddle
...
...
@@ -60,11 +61,12 @@ class BasePredictor(object):
return
out
def
preprocess
(
self
,
inputs
):
pass
def
postprocess
(
self
,
inputs
):
pass
def
is_video
(
self
,
input
):
try
:
cv2
.
VideoCapture
(
input
)
return
True
except
:
return
False
def
run
(
self
):
pass
raise
NotImplementedError
ppgan/apps/deoldify_predictor.py
浏览文件 @
1744b3a6
...
...
@@ -77,8 +77,14 @@ class DeOldifyPredictor(BasePredictor):
final
=
Image
.
fromarray
(
final
)
return
final
def
run_single
(
self
,
img_path
):
ori_img
=
Image
.
open
(
img_path
).
convert
(
'LA'
).
convert
(
'RGB'
)
def
run_image
(
self
,
img
):
if
isinstance
(
img
,
str
):
ori_img
=
Image
.
open
(
img
).
convert
(
'LA'
).
convert
(
'RGB'
)
elif
isinstance
(
img
,
np
.
ndarray
):
ori_img
=
Image
.
fromarray
(
img
).
convert
(
'LA'
).
convert
(
'RGB'
)
elif
isinstance
(
img
,
Image
.
Image
):
ori_img
=
img
img
=
self
.
norm
(
ori_img
,
self
.
render_factor
)
x
=
paddle
.
to_tensor
(
img
[
np
.
newaxis
,
...])
out
=
self
.
model
(
x
)
...
...
@@ -89,8 +95,8 @@ class DeOldifyPredictor(BasePredictor):
pred_img
=
self
.
post_process
(
pred_img
,
ori_img
)
return
pred_img
def
run
(
self
,
video_path
):
base_name
=
os
.
path
.
basename
(
video
_path
).
split
(
'.'
)[
0
]
def
run
_video
(
self
,
video
):
base_name
=
os
.
path
.
basename
(
video
).
split
(
'.'
)[
0
]
output_path
=
os
.
path
.
join
(
self
.
output
,
base_name
)
pred_frame_path
=
os
.
path
.
join
(
output_path
,
'frames_pred'
)
...
...
@@ -100,15 +106,15 @@ class DeOldifyPredictor(BasePredictor):
if
not
os
.
path
.
exists
(
pred_frame_path
):
os
.
makedirs
(
pred_frame_path
)
cap
=
cv2
.
VideoCapture
(
video
_path
)
cap
=
cv2
.
VideoCapture
(
video
)
fps
=
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
out_path
=
video2frames
(
video
_path
,
output_path
)
out_path
=
video2frames
(
video
,
output_path
)
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
out_path
,
'*.png'
)))
for
frame
in
tqdm
(
frames
):
pred_img
=
self
.
run_
singl
e
(
frame
)
pred_img
=
self
.
run_
imag
e
(
frame
)
frame_name
=
os
.
path
.
basename
(
frame
)
pred_img
.
save
(
os
.
path
.
join
(
pred_frame_path
,
frame_name
))
...
...
@@ -120,3 +126,15 @@ class DeOldifyPredictor(BasePredictor):
frames2video
(
frame_pattern_combined
,
vid_out_path
,
str
(
int
(
fps
)))
return
frame_pattern_combined
,
vid_out_path
def
run
(
self
,
input
):
if
self
.
is_video
(
input
):
return
self
.
run_video
(
input
)
else
:
pred_img
=
self
.
run_image
(
input
)
if
self
.
output
:
base_name
=
os
.
path
.
basename
(
input
)
pred_img
.
save
(
os
.
path
.
join
(
self
.
output
,
base_name
+
'.png'
))
return
pred_img
ppgan/apps/realsr_predictor.py
浏览文件 @
1744b3a6
...
...
@@ -49,8 +49,14 @@ class RealSRPredictor(BasePredictor):
img
=
img
.
transpose
((
1
,
2
,
0
))
return
(
img
*
255
).
clip
(
0
,
255
).
astype
(
'uint8'
)
def
run_single
(
self
,
img_path
):
ori_img
=
Image
.
open
(
img_path
).
convert
(
'RGB'
)
def
run_image
(
self
,
img
):
if
isinstance
(
img
,
str
):
ori_img
=
Image
.
open
(
img
).
convert
(
'RGB'
)
elif
isinstance
(
img
,
np
.
ndarray
):
ori_img
=
Image
.
fromarray
(
img
).
convert
(
'RGB'
)
elif
isinstance
(
img
,
Image
.
Image
):
ori_img
=
img
img
=
self
.
norm
(
ori_img
)
x
=
paddle
.
to_tensor
(
img
[
np
.
newaxis
,
...])
out
=
self
.
model
(
x
)
...
...
@@ -59,9 +65,8 @@ class RealSRPredictor(BasePredictor):
pred_img
=
Image
.
fromarray
(
pred_img
)
return
pred_img
def
run
(
self
,
video_path
):
vid
=
video_path
base_name
=
os
.
path
.
basename
(
vid
).
split
(
'.'
)[
0
]
def
run_video
(
self
,
video
):
base_name
=
os
.
path
.
basename
(
video
).
split
(
'.'
)[
0
]
output_path
=
os
.
path
.
join
(
self
.
output
,
base_name
)
pred_frame_path
=
os
.
path
.
join
(
output_path
,
'frames_pred'
)
...
...
@@ -71,15 +76,15 @@ class RealSRPredictor(BasePredictor):
if
not
os
.
path
.
exists
(
pred_frame_path
):
os
.
makedirs
(
pred_frame_path
)
cap
=
cv2
.
VideoCapture
(
vid
)
cap
=
cv2
.
VideoCapture
(
vid
eo
)
fps
=
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
out_path
=
video2frames
(
vid
,
output_path
)
out_path
=
video2frames
(
vid
eo
,
output_path
)
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
out_path
,
'*.png'
)))
for
frame
in
tqdm
(
frames
):
pred_img
=
self
.
run_
singl
e
(
frame
)
pred_img
=
self
.
run_
imag
e
(
frame
)
frame_name
=
os
.
path
.
basename
(
frame
)
pred_img
.
save
(
os
.
path
.
join
(
pred_frame_path
,
frame_name
))
...
...
@@ -91,3 +96,15 @@ class RealSRPredictor(BasePredictor):
frames2video
(
frame_pattern_combined
,
vid_out_path
,
str
(
int
(
fps
)))
return
frame_pattern_combined
,
vid_out_path
def
run
(
self
,
input
):
if
self
.
is_video
(
input
):
return
self
.
run_video
(
input
)
else
:
pred_img
=
self
.
run_image
(
input
)
if
self
.
output
:
base_name
=
os
.
path
.
basename
(
input
)
pred_img
.
save
(
os
.
path
.
join
(
self
.
output
,
base_name
+
'.png'
))
return
pred_img
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录