Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
6504ef76
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6504ef76
编写于
8月 29, 2023
作者:
T
Tingquan Gao
提交者:
GitHub
8月 29, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support to chinese in draw_bbox (#8581)
上级
249de9bd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
12 deletion
+19
-12
ppdet/utils/compact.py
ppdet/utils/compact.py
+4
-4
ppdet/utils/download.py
ppdet/utils/download.py
+5
-5
ppdet/utils/simfang.ttf
ppdet/utils/simfang.ttf
+0
-0
ppdet/utils/visualizer.py
ppdet/utils/visualizer.py
+10
-3
未找到文件。
ppdet/utils/compact.py
浏览文件 @
6504ef76
import
PIL
def
imagedraw_textsize_c
(
draw
,
text
):
def
imagedraw_textsize_c
(
draw
,
text
,
font
=
None
):
if
int
(
PIL
.
__version__
.
split
(
'.'
)[
0
])
<
10
:
tw
,
th
=
draw
.
textsize
(
text
)
tw
,
th
=
draw
.
textsize
(
text
,
font
=
font
)
else
:
left
,
top
,
right
,
bottom
=
draw
.
textbbox
((
0
,
0
),
text
)
left
,
top
,
right
,
bottom
=
draw
.
textbbox
((
0
,
0
),
text
,
font
=
font
)
tw
,
th
=
right
-
left
,
bottom
-
top
return
tw
,
th
\ No newline at end of file
ppdet/utils/download.py
浏览文件 @
6504ef76
...
...
@@ -237,7 +237,7 @@ def create_voc_list(data_dir, devkit_subdir='VOCdevkit'):
years
=
[
'2007'
,
'2012'
]
# NOTE: since using auto download VOC
# dataset, VOC default label list should be used,
# dataset, VOC default label list should be used,
# do not generate label_list.txt here. For default
# label, see ../data/source/voc.py
create_list
(
devkit_dir
,
years
,
data_dir
)
...
...
@@ -296,7 +296,7 @@ def get_path(url, root_dir, md5sum=None, check_exist=True):
# new weights format which postfix is 'pdparams' not
# need to decompress
if
osp
.
splitext
(
fullname
)[
-
1
]
not
in
[
'.pdparams'
,
'.yml'
]:
if
osp
.
splitext
(
fullname
)[
-
1
]
not
in
[
'.pdparams'
,
'.yml'
,
'.ttf'
]:
_decompress_dist
(
fullname
)
return
fullpath
,
False
...
...
@@ -411,7 +411,7 @@ def _download_dist(url, path, md5sum=None):
must_mkdirs
(
path
)
if
not
osp
.
exists
(
fullname
):
with
open
(
lock_path
,
'w'
):
# touch
with
open
(
lock_path
,
'w'
):
# touch
os
.
utime
(
lock_path
,
None
)
if
rank_id_curr_node
==
0
:
_download
(
url
,
path
,
md5sum
)
...
...
@@ -425,7 +425,7 @@ def _download_dist(url, path, md5sum=None):
def
_check_exist_file_md5
(
filename
,
md5sum
,
url
):
# if md5sum is None, and file to check is weights file,
# if md5sum is None, and file to check is weights file,
# read md5um from url and check, else check md5sum directly
return
_md5check_from_url
(
filename
,
url
)
if
md5sum
is
None
\
and
filename
.
endswith
(
'pdparams'
)
\
...
...
@@ -525,7 +525,7 @@ def _decompress_dist(fname):
# trainer pipeline in order
# **change this if you have more elegent methods**
if
ParallelEnv
().
current_endpoint
in
unique_endpoints
:
with
open
(
lock_path
,
'w'
):
# touch
with
open
(
lock_path
,
'w'
):
# touch
os
.
utime
(
lock_path
,
None
)
_decompress
(
fname
)
os
.
remove
(
lock_path
)
...
...
ppdet/utils/simfang.ttf
0 → 100644
浏览文件 @
6504ef76
文件已添加
ppdet/utils/visualizer.py
浏览文件 @
6504ef76
...
...
@@ -17,14 +17,16 @@ from __future__ import division
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
os
import
numpy
as
np
from
PIL
import
Image
,
ImageDraw
from
PIL
import
Image
,
ImageDraw
,
ImageFont
import
cv2
import
math
from
.colormap
import
colormap
from
ppdet.utils.logger
import
setup_logger
from
ppdet.utils.compact
import
imagedraw_textsize_c
from
ppdet.utils.download
import
get_path
logger
=
setup_logger
(
__name__
)
__all__
=
[
'visualize_results'
]
...
...
@@ -86,6 +88,11 @@ def draw_bbox(image, im_id, catid2name, bboxes, threshold):
"""
Draw bbox on image
"""
font_url
=
"https://paddledet.bj.bcebos.com/simfang.ttf"
font_path
,
_
=
get_path
(
font_url
,
"~/.cache/paddle/"
)
font_size
=
18
font
=
ImageFont
.
truetype
(
font_path
,
font_size
,
encoding
=
"utf-8"
)
draw
=
ImageDraw
.
Draw
(
image
)
catid2color
=
{}
...
...
@@ -126,10 +133,10 @@ def draw_bbox(image, im_id, catid2name, bboxes, threshold):
# draw label
text
=
"{} {:.2f}"
.
format
(
catid2name
[
catid
],
score
)
tw
,
th
=
imagedraw_textsize_c
(
draw
,
text
)
tw
,
th
=
imagedraw_textsize_c
(
draw
,
text
,
font
=
font
)
draw
.
rectangle
(
[(
xmin
+
1
,
ymin
-
th
),
(
xmin
+
tw
+
1
,
ymin
)],
fill
=
color
)
draw
.
text
((
xmin
+
1
,
ymin
-
th
),
text
,
fill
=
(
255
,
255
,
255
))
draw
.
text
((
xmin
+
1
,
ymin
-
th
),
text
,
fill
=
(
255
,
255
,
255
)
,
font
=
font
)
return
image
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录