Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleGAN
提交
4cd9a0b1
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
4cd9a0b1
编写于
9月 28, 2020
作者:
Q
qingqing01
提交者:
GitHub
9月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #28 from lijianshe02/master
add remove duplicate frames in DAIN
上级
58154147
c02f4070
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
91 addition
and
58 deletion
+91
-58
applications/DAIN/my_args.py
applications/DAIN/my_args.py
+4
-1
applications/DAIN/predict.py
applications/DAIN/predict.py
+55
-57
applications/DAIN/util.py
applications/DAIN/util.py
+32
-0
未找到文件。
applications/DAIN/my_args.py
浏览文件 @
4cd9a0b1
...
@@ -90,4 +90,7 @@ parser.add_argument('--use_cuda',
...
@@ -90,4 +90,7 @@ parser.add_argument('--use_cuda',
type
=
bool
,
type
=
bool
,
help
=
'use cuda or not'
)
help
=
'use cuda or not'
)
parser
.
add_argument
(
'--use_cudnn'
,
default
=
1
,
type
=
int
,
help
=
'use cudnn or not'
)
parser
.
add_argument
(
'--use_cudnn'
,
default
=
1
,
type
=
int
,
help
=
'use cudnn or not'
)
parser
.
add_argument
(
'--remove_duplicates'
,
default
=
True
,
type
=
bool
,
help
=
'remove duplicate frames or not'
)
applications/DAIN/predict.py
浏览文件 @
4cd9a0b1
...
@@ -80,7 +80,8 @@ class VideoFrameInterp(object):
...
@@ -80,7 +80,8 @@ class VideoFrameInterp(object):
video_path
,
video_path
,
use_gpu
=
True
,
use_gpu
=
True
,
key_frame_thread
=
0.
,
key_frame_thread
=
0.
,
output_path
=
'output'
):
output_path
=
'output'
,
remove_duplicates
=
True
):
self
.
video_path
=
video_path
self
.
video_path
=
video_path
self
.
output_path
=
os
.
path
.
join
(
output_path
,
'DAIN'
)
self
.
output_path
=
os
.
path
.
join
(
output_path
,
'DAIN'
)
if
model_path
is
None
:
if
model_path
is
None
:
...
@@ -138,6 +139,8 @@ class VideoFrameInterp(object):
...
@@ -138,6 +139,8 @@ class VideoFrameInterp(object):
end
=
time
.
time
()
end
=
time
.
time
()
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
out_path
,
'*.png'
)))
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
out_path
,
'*.png'
)))
if
remove_duplicates
:
frames
=
remove_duplicates
(
out_path
)
img
=
imread
(
frames
[
0
])
img
=
imread
(
frames
[
0
])
...
@@ -199,12 +202,6 @@ class VideoFrameInterp(object):
...
@@ -199,12 +202,6 @@ class VideoFrameInterp(object):
X0
=
img_first
.
astype
(
'float32'
).
transpose
((
2
,
0
,
1
))
/
255
X0
=
img_first
.
astype
(
'float32'
).
transpose
((
2
,
0
,
1
))
/
255
X1
=
img_second
.
astype
(
'float32'
).
transpose
((
2
,
0
,
1
))
/
255
X1
=
img_second
.
astype
(
'float32'
).
transpose
((
2
,
0
,
1
))
/
255
if
key_frame
:
y_
=
[
np
.
transpose
(
255.0
*
X0
.
clip
(
0
,
1.0
),
(
1
,
2
,
0
))
for
i
in
range
(
num_frames
)
]
else
:
assert
(
X0
.
shape
[
1
]
==
X1
.
shape
[
1
])
assert
(
X0
.
shape
[
1
]
==
X1
.
shape
[
1
])
assert
(
X0
.
shape
[
2
]
==
X1
.
shape
[
2
])
assert
(
X0
.
shape
[
2
]
==
X1
.
shape
[
2
])
...
@@ -235,8 +232,7 @@ class VideoFrameInterp(object):
...
@@ -235,8 +232,7 @@ class VideoFrameInterp(object):
y_
=
[
y_
=
[
np
.
transpose
(
np
.
transpose
(
255.0
*
item
.
clip
(
255.0
*
item
.
clip
(
0
,
1.0
)[
0
,
:,
0
,
1.0
)[
0
,
:,
padding_top
:
padding_top
+
int_height
,
padding_top
:
padding_top
+
int_height
,
padding_left
:
padding_left
+
int_width
],
padding_left
:
padding_left
+
int_width
],
(
1
,
2
,
0
))
for
item
in
y_
(
1
,
2
,
0
))
for
item
in
y_
]
]
...
@@ -266,14 +262,16 @@ class VideoFrameInterp(object):
...
@@ -266,14 +262,16 @@ class VideoFrameInterp(object):
vidname
+
'.mp4'
)
vidname
+
'.mp4'
)
if
os
.
path
.
exists
(
video_pattern_output
):
if
os
.
path
.
exists
(
video_pattern_output
):
os
.
remove
(
video_pattern_output
)
os
.
remove
(
video_pattern_output
)
frames2video
(
frame_pattern_combined
,
video_pattern_output
,
frames2video
(
frame_pattern_combined
,
video_pattern_output
,
r2
)
r2
)
return
frame_pattern_combined
,
video_pattern_output
return
frame_pattern_combined
,
video_pattern_output
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
predictor
=
VideoFrameInterp
(
args
.
time_step
,
args
.
saved_model
,
predictor
=
VideoFrameInterp
(
args
.
time_step
,
args
.
video_path
,
args
.
output_path
)
args
.
saved_model
,
args
.
video_path
,
args
.
output_path
,
remove_duplicates
=
args
.
remove_duplicates
)
predictor
.
run
()
predictor
.
run
()
applications/DAIN/util.py
浏览文件 @
4cd9a0b1
import
os
,
sys
import
os
,
sys
import
glob
import
glob
import
shutil
import
shutil
import
cv2
class
AverageMeter
(
object
):
class
AverageMeter
(
object
):
...
@@ -44,3 +45,34 @@ def combine_frames(input, interpolated, combined, num_frames):
...
@@ -44,3 +45,34 @@ def combine_frames(input, interpolated, combined, num_frames):
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
print
(
e
)
print
(
len
(
frames2
),
num_frames
,
i
,
k
,
i
*
num_frames
+
k
)
print
(
len
(
frames2
),
num_frames
,
i
,
k
,
i
*
num_frames
+
k
)
def
remove_duplicates
(
paths
):
def
dhash
(
image
,
hash_size
=
8
):
gray
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2GRAY
)
resized
=
cv2
.
resize
(
gray
,
(
hash_size
+
1
,
hash_size
))
diff
=
resized
[:,
1
:]
>
resized
[:,
:
-
1
]
return
sum
([
2
**
i
for
(
i
,
v
)
in
enumerate
(
diff
.
flatten
())
if
v
])
hashes
=
{}
image_paths
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
paths
,
'*.png'
)))
for
image_path
in
image_paths
:
image
=
cv2
.
imread
(
image_path
)
h
=
dhash
(
image
)
p
=
hashes
.
get
(
h
,
[])
p
.
append
(
image_path
)
hashes
[
h
]
=
p
for
(
h
,
hashed_paths
)
in
hashes
.
items
():
if
len
(
hashed_paths
)
>
1
:
for
p
in
hashed_paths
[
1
:]:
os
.
remove
(
p
)
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
paths
,
'*.png'
)))
for
fid
,
frame
in
enumerate
(
frames
):
new_name
=
'{:08d}'
.
format
(
fid
)
+
'.png'
new_name
=
os
.
path
.
join
(
paths
,
new_name
)
os
.
rename
(
frame
,
new_name
)
frames
=
sorted
(
glob
.
glob
(
os
.
path
.
join
(
paths
,
'*.png'
)))
return
frames
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录