Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
74a33b7f
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
74a33b7f
编写于
9月 01, 2023
作者:
Z
zhangyubo0722
提交者:
GitHub
9月 01, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gbk (#2941)
上级
b3fcc986
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
23 deletion
+36
-23
ppcls/data/postprocess/topk.py
ppcls/data/postprocess/topk.py
+6
-2
ppcls/data/utils/get_image_list.py
ppcls/data/utils/get_image_list.py
+21
-12
ppcls/engine/engine.py
ppcls/engine/engine.py
+6
-3
ppcls/utils/save_result.py
ppcls/utils/save_result.py
+3
-6
未找到文件。
ppcls/data/postprocess/topk.py
浏览文件 @
74a33b7f
...
...
@@ -36,8 +36,12 @@ class Topk(object):
try
:
class_id_map
=
{}
with
open
(
class_id_map_file
,
"r"
)
as
fin
:
lines
=
fin
.
readlines
()
try
:
with
open
(
class_id_map_file
,
"r"
,
encoding
=
'utf-8'
)
as
fin
:
lines
=
fin
.
readlines
()
except
Exception
as
e
:
with
open
(
class_id_map_file
,
"r"
,
encoding
=
'gbk'
)
as
fin
:
lines
=
fin
.
readlines
()
for
line
in
lines
:
partition
=
line
.
split
(
"
\n
"
)[
0
].
partition
(
self
.
delimiter
)
class_id_map
[
int
(
partition
[
0
])]
=
str
(
partition
[
-
1
])
...
...
ppcls/data/utils/get_image_list.py
浏览文件 @
74a33b7f
...
...
@@ -18,19 +18,28 @@ import base64
import
numpy
as
np
def
get_image_list
(
img_file
):
def
get_image_list
(
img_file
,
infer_list
=
None
):
imgs_lists
=
[]
if
img_file
is
None
or
not
os
.
path
.
exists
(
img_file
):
raise
Exception
(
"not found any img file in {}"
.
format
(
img_file
))
img_end
=
[
'jpg'
,
'png'
,
'jpeg'
,
'JPEG'
,
'JPG'
,
'bmp'
]
if
os
.
path
.
isfile
(
img_file
)
and
img_file
.
split
(
'.'
)[
-
1
]
in
img_end
:
imgs_lists
.
append
(
img_file
)
elif
os
.
path
.
isdir
(
img_file
):
for
root
,
dirs
,
files
in
os
.
walk
(
img_file
):
for
single_file
in
files
:
if
single_file
.
split
(
'.'
)[
-
1
]
in
img_end
:
imgs_lists
.
append
(
os
.
path
.
join
(
root
,
single_file
))
if
infer_list
and
not
os
.
path
.
exists
(
infer_list
):
raise
Exception
(
"not found infer list {}"
.
format
(
infer_list
))
if
infer_list
:
with
open
(
infer_list
,
"r"
)
as
f
:
lines
=
f
.
readlines
()
for
line
in
lines
:
image_path
=
line
.
strip
(
" "
).
split
()[
0
]
image_path
=
os
.
path
.
join
(
img_file
,
image_path
)
imgs_lists
.
append
(
image_path
)
else
:
if
img_file
is
None
or
not
os
.
path
.
exists
(
img_file
):
raise
Exception
(
"not found any img file in {}"
.
format
(
img_file
))
img_end
=
[
'jpg'
,
'png'
,
'jpeg'
,
'JPEG'
,
'JPG'
,
'bmp'
]
if
os
.
path
.
isfile
(
img_file
)
and
img_file
.
split
(
'.'
)[
-
1
]
in
img_end
:
imgs_lists
.
append
(
img_file
)
elif
os
.
path
.
isdir
(
img_file
):
for
root
,
dirs
,
files
in
os
.
walk
(
img_file
):
for
single_file
in
files
:
if
single_file
.
split
(
'.'
)[
-
1
]
in
img_end
:
imgs_lists
.
append
(
os
.
path
.
join
(
root
,
single_file
))
if
len
(
imgs_lists
)
==
0
:
raise
Exception
(
"not found any img file in {}"
.
format
(
img_file
))
imgs_lists
=
sorted
(
imgs_lists
)
...
...
ppcls/engine/engine.py
100755 → 100644
浏览文件 @
74a33b7f
...
...
@@ -442,7 +442,9 @@ class Engine(object):
results
=
[]
total_trainer
=
dist
.
get_world_size
()
local_rank
=
dist
.
get_rank
()
image_list
=
get_image_list
(
self
.
config
[
"Infer"
][
"infer_imgs"
])
infer_imgs
=
self
.
config
[
"Infer"
][
"infer_imgs"
]
infer_list
=
self
.
config
[
"Infer"
].
get
(
"infer_list"
,
None
)
image_list
=
get_image_list
(
infer_imgs
,
infer_list
=
infer_list
)
# data split
image_list
=
image_list
[
local_rank
::
total_trainer
]
...
...
@@ -450,6 +452,7 @@ class Engine(object):
self
.
model
.
eval
()
batch_data
=
[]
image_file_list
=
[]
save_path
=
self
.
config
[
"Infer"
].
get
(
"save_dir"
,
None
)
for
idx
,
image_file
in
enumerate
(
image_list
):
with
open
(
image_file
,
'rb'
)
as
f
:
x
=
f
.
read
()
...
...
@@ -473,11 +476,11 @@ class Engine(object):
out
=
out
[
"output"
]
result
=
self
.
postprocess_func
(
out
,
image_file_list
)
logger
.
info
(
result
)
if
not
save_path
:
logger
.
info
(
result
)
results
.
extend
(
result
)
batch_data
.
clear
()
image_file_list
.
clear
()
save_path
=
self
.
config
[
"Infer"
].
get
(
"save_dir"
,
None
)
if
save_path
:
save_predict_result
(
save_path
,
results
)
return
results
...
...
ppcls/utils/save_result.py
浏览文件 @
74a33b7f
...
...
@@ -24,12 +24,9 @@ def save_predict_result(save_path, result):
elif
os
.
path
.
splitext
(
save_path
)[
-
1
]
==
'.json'
:
save_path
=
save_path
else
:
logger
.
warning
(
f
"
{
save_path
}
is invalid input path, only files in json format are supported."
)
raise
Exception
(
f
"
{
save_path
}
is invalid input path, only files in json format are supported."
)
if
os
.
path
.
exists
(
save_path
):
logger
.
warning
(
f
"The file
{
save_path
}
will be overwritten."
)
logger
.
warning
(
f
"The file
{
save_path
}
will be overwritten."
)
with
open
(
save_path
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
json
.
dump
(
result
,
f
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录