(YOLOv5-7.0版本后) 如何让中文标签正常显示

博主在被最新版的yolov5整痛苦面具。(中文乱码)
在detect.py上

模型挂载上出了问题(没统一用一个模型)...

def run(
        weights=ROOT / 'best_updated.pt',  # model path or triton URL
def parse_opt():
    parser = argparse.ArgumentParser()
    parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'best_updated.pt', help='model path or triton URL')

 问题中文乱码,解决后

尝试过的办法:
1.在detect.py文件库,ctrl按住点击Annotator

 修改默认代码的Arial.ttf为sihei.ttf

def __init__(self, im, line_width=None, font_size=None, font='simhei.ttf', pil=False, example='abc'):
    """Initialize the Annotator class with image and line width along with color palette for keypoints and limbs."""
    assert im.data.contiguous, 'Image not contiguous. Apply np.ascontiguousarray(im) to Annotator() input images.'
    non_ascii = not is_ascii(example)  # non-latin labels, i.e. asian, arabic, cyrillic
    self.pil = pil or non_ascii
    self.lw = line_width or max(round(sum(im.shape) / 2 * 0.003), 2)  # line width
    if self.pil:  # use PIL
        self.im = im if isinstance(im, Image.Image) else Image.fromarray(im)
        self.draw = ImageDraw.Draw(self.im)
        try:
            font = check_font('simhei.ttf' if non_ascii else font)
            省略代码

2.在utils/plots.py文件前面添加(没感觉有用,我训练完模型用中文标签的)

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

 

 3.在utils/metrics.py文件前面添加

plt.rcParams['font.sans-serif'] = ['simhei']
plt.rcParams['axes.unicode_minus'] = False

4.在utils/general.py文件修改def yaml_load(编码方式改成gbk)

def yaml_load(file='data.yaml'):
    # Single-line safe yaml loading
    with open(file, encoding='gbk', errors='ignore') as f:
        return yaml.safe_load(f)

【精选】YOLOv5 完美实现中文标签显示-CSDN博客 感谢大佬提供解决方案

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值