Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
周伟奇
/
test_on_pytorch
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f5b96f19
authored
2022-12-22 19:32:52 +0800
by
周伟奇
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix bug
1 parent
41252450
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
33 deletions
data/create_dataset2.py
solver/sl_solver.py
data/create_dataset2.py
View file @
f5b96f1
...
...
@@ -300,7 +300,7 @@ def build_dataset(img_dir, go_res_dir, label_dir, top_text_list, skip_list, save
if
__name__
==
'__main__'
:
base_dir
=
'/Users/zhouweiqi/Downloads/gcfp/data'
go_dir
=
os
.
path
.
join
(
base_dir
,
'go_res'
)
dataset_save_dir
=
os
.
path
.
join
(
base_dir
,
'dataset160x14-pro'
)
dataset_save_dir
=
os
.
path
.
join
(
base_dir
,
'dataset160x14-pro
-all-valid
'
)
label_dir
=
os
.
path
.
join
(
base_dir
,
'labeled'
)
train_go_path
=
os
.
path
.
join
(
go_dir
,
'train'
)
...
...
@@ -360,14 +360,14 @@ if __name__ == '__main__':
]
skip_list_train
=
[
#
'CH-B101910792-page-12.jpg',
#
'CH-B101655312-page-13.jpg',
#
'CH-B102278656.jpg',
#
'CH-B101846620_page_1_img_0.jpg',
#
'CH-B103062528-0.jpg',
#
'CH-B102613120-3.jpg',
#
'CH-B102997980-3.jpg',
#
'CH-B102680060-3.jpg',
'CH-B101910792-page-12.jpg'
,
'CH-B101655312-page-13.jpg'
,
'CH-B102278656.jpg'
,
'CH-B101846620_page_1_img_0.jpg'
,
'CH-B103062528-0.jpg'
,
'CH-B102613120-3.jpg'
,
'CH-B102997980-3.jpg'
,
'CH-B102680060-3.jpg'
,
# # 'CH-B102995500-2.jpg', # 没value
]
...
...
solver/sl_solver.py
View file @
f5b96f1
...
...
@@ -292,36 +292,36 @@ class SLSolver(object):
bbox_text_dict
=
dict
()
for
i
in
range
(
valid_lens_scalar
):
if
pred
[
i
]
!=
0
:
bbox_text_dict
.
setdefault
(
test_group_id
[
pred
[
i
]
-
1
]
,
list
())
.
append
(
i
)
bbox_text_dict
.
setdefault
(
pred
[
i
]
-
1
,
list
())
.
append
(
i
)
if
pred
[
i
]
==
label
[
i
]:
correct
+=
1
if
pred
[
i
]
!=
0
:
# 绿色
bbox_draw_dict
[
i
]
=
(
group_cn_list
[
pred
[
i
]],
)
else
:
# 红色:左上角label,右上角pred
bbox_draw_dict
[
i
]
=
(
group_cn_list
[
label
[
i
]],
group_cn_list
[
pred
[
i
]])
#
if pred[i] == label[i]:
#
correct += 1
#
if pred[i] != 0:
#
# 绿色
#
bbox_draw_dict[i] = (group_cn_list[pred[i]], )
#
else:
#
# 红色:左上角label,右上角pred
#
bbox_draw_dict[i] = (group_cn_list[label[i]], group_cn_list[pred[i]])
correct_rate
=
correct
/
valid_lens_scalar
#
correct_rate = correct / valid_lens_scalar
# 画图
for
idx
,
text_tuple
in
bbox_draw_dict
.
items
():
(
x0
,
y0
,
x1
,
y1
,
x2
,
y2
,
x3
,
y3
),
_
=
go_res_list
[
idx
]
line_color
=
green_color
if
len
(
text_tuple
)
==
1
else
red_color
draw
.
polygon
([(
x0
,
y0
),
(
x1
,
y1
),
(
x2
,
y2
),
(
x3
,
y3
)],
outline
=
line_color
)
draw
.
text
((
int
(
x0
),
int
(
y0
)),
text_tuple
[
0
],
green_color
,
font
=
font
)
if
len
(
text_tuple
)
==
2
:
draw
.
text
((
int
(
x1
),
int
(
y1
)),
text_tuple
[
1
],
red_color
,
font
=
font
)
#
for idx, text_tuple in bbox_draw_dict.items():
#
(x0, y0, x1, y1, x2, y2, x3, y3), _ = go_res_list[idx]
#
line_color = green_color if len(text_tuple) == 1 else red_color
#
draw.polygon([(x0, y0), (x1, y1), (x2, y2), (x3, y3)], outline=line_color)
#
draw.text((int(x0), int(y0)), text_tuple[0], green_color, font=font)
#
if len(text_tuple) == 2:
#
draw.text((int(x1), int(y1)), text_tuple[1], red_color, font=font)
draw
.
text
((
0
,
0
),
str
(
correct_rate
),
blue_color
,
font
=
font
)
#
draw.text((0, 0), str(correct_rate), blue_color, font=font)
last_y
=
size
for
k
,
v
in
val_map
[
img_name
][
map_key_value
]
.
items
():
draw
.
text
((
0
,
last_y
),
'{0}: {1}'
.
format
(
k
,
v
),
blue_color
,
font
=
font
)
last_y
+=
size
#
last_y = size
#
for k, v in val_map[img_name][map_key_value].items():
#
draw.text((0, last_y), '{0}: {1}'.format(k, v), blue_color, font=font)
#
last_y += size
img_pil
.
save
(
os
.
path
.
join
(
save_dir
,
img_name
))
#
img_pil.save(os.path.join(save_dir, img_name))
# 统计准确率
label_json_path
=
os
.
path
.
join
(
self
.
val_label_path
,
'{0}.json'
.
format
(
base_image_name
))
...
...
@@ -355,7 +355,7 @@ class SLSolver(object):
# break
for
key_cn
,
(
correct_count
,
all_count
)
in
data_dict
.
i
et
ms
():
for
key_cn
,
(
correct_count
,
all_count
)
in
data_dict
.
i
te
ms
():
print
(
'{0}: {1}'
.
format
(
key_cn
,
round
(
correct_count
/
all_count
,
2
)))
print
(
'==========================='
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment