本系列主要用于自我学习,参考的为bubbliiiing的代码
写一个优雅的:从txt文件中获得类别名与类别数的函数,如下:
#---------------------------------------------------#
# 获得类别名与类别数
#---------------------------------------------------#
def get_classes(classes_path):
with open(classes_path, encoding='utf-8') as f:
class_names = f.readlines()
class_names = [c.strip() for c in class_names]
return class_names, len(class_names)
if __name__ == "__main__":
classes_path = 'model_data/voc_classes.txt'
class_names, num_classes = get_classes(classes_path)