当前位置:   article > 正文

(YOLOv5-7.0版本后) 如何让中文标签正常显示_yolov5怎么将标签改成中文

yolov5怎么将标签改成中文

博主在被最新版的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博客 感谢大佬提供解决方案

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/797374
推荐阅读
  

闽ICP备14008679号