博主在被最新版的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
![](https://img-blog.csdnimg.cn/aae80ea838894400b68bed815287c081.png)
修改默认代码的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博客 感谢大佬提供解决方案