python版本faster rcnn代码中,使用pascal_voc类型数据进行训练时,pascal_voc初始化时,self._classes是直接赋值的,如self._classes = ('__background__', '2','research'),当类别数较多时,此方法容易遗漏类别号,因此修改为从文件读取的方式。
#coding:utf-8
import os
def obtainclsname(path):
pclslist = ['__background']
frcls = open(path,'r')
for line in frcls:
line = line.split()
print ('line is : ', line[0])
pclslist.append(line[0])
frcls.close()
tup = tuple(pclslist)
return tup
def obtainclsname2(path):
pclslist = ['__background']
with open(path,'r') as frcls:
for line in frcls:
line = line.split()
print ('line is : ', line[0])
pclslist.append(line[0])
return tuple(pclslist)
if __name__ == '__main__':
path = 'E:/VOC2007/card/clsname.txt'
pq = obtainclsname(path)
print pq
pqw = obtainclsname2(path)
print pqw
假设,存储类别的txt文件为:
则在pscal_voc.py中,执行以下操作:
则self._classes为: