当前位置:   article > 正文

Yolov5修改支持中文标签训练_yolov5训练集可以是中文吗

yolov5训练集可以是中文吗

step1:在yolov5course\yolov5-master\utils路径下找到general.py文件,修改yaml_loda函数改为下图

  1. def yaml_load(file='data.yaml'):
  2. # Single-line safe yaml loading
  3. #with open(file, errors='ignore') as f:
  4. with open(file, errors='ignore',encoding='UTF-8') as f:
  5. return yaml.safe_load(f)
'
运行
step2:在yolov5course\yolov5-master\utils路径下找到plots.py文件,在setting注释栏下面添加代码,如下图
  1. # Settings
  2. RANK = int(os.getenv('RANK', -1))
  3. matplotlib.rc('font', **{'size': 11})
  4. matplotlib.use('Agg') # for writing to files only
  5. plt.rcParams['font.sans-serif'] = ["SimHei"]
  6. plt.rcParams['axes.unicode_minus'] = False

step3:在yolov5course\yolov5-master\utils路径下找metrics.py文件,找到plot函数如图修改

  1. def plot(self, normalize=True, save_dir='', names=()):
  2. import seaborn as sn
  3. rc = {'font.sans-serif': ['SimHei']}
  4. array = self.matrix / ((self.matrix.sum(0).reshape(1, -1) + 1E-9) if normalize else 1) # normalize columns
  5. array[array < 0.005] = np.nan # don't annotate (would appear as 0.00)
  6. fig, ax = plt.subplots(1, 1, figsize=(12, 9), tight_layout=True)
  7. nc, nn = self.nc, len(names) # number of classes, names
  8. sn.set(font_scale=1.0 if nc < 50 else 0.8,rc=rc) # for label size
  9. labels = (0 < nn < 99) and (nn == nc) # apply names to ticklabels
  10. ticklabels = (names + ['background']) if labels else "auto"

PS:若matplotlib库中没有SimHei.ttf,请自行手动安装安装链接:https://us-logger1.oss-cn-beijing.aliyuncs.com/SimHei.ttf

训练前请确保yaml文件中标签类为中文

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

闽ICP备14008679号