xml文件转化成tfrecord格式出现错误TypeError: None has type NoneType, but expected one of: int, long
具体报错内容如下:
in csv2tfrecord(csv_path, imageDir_path, tfrecord_path)
30 ‘image/object/bbox/ymax’: dataset_util.float_list_feature(ymax_list),
31 ‘image/object/class/text’: dataset_util.bytes_list_feature(classText_list),
—> 32 ‘image/object/class/label’: dataset_util.int64_list_feature(classLabel_list),
33 }))
34 tfrecord_writer.write(tf_example.SerializeToString())
E:\AI_Codes\models-master\research\object_detection\utils\dataset_util.py in int64_list_feature(value)
24
25 def int64_list_feature(value):
—> 26 return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
27
28
原因分析:
此错误是由于训练集标注不全或错误而引起的,应检查训练集以及测试集里的照片是否和生成的xml文件一一对应,改正之后,需要重新生成csv数据。
解决过程:
报错中提示返回None,说明肯定是代码哪里写了,根据报错在“classLabel_list ” 找到classLabel_list = [classText_to_classLabel(classText) for classText in group[‘class’]]
这一行,进而找到了“classText_to_classLabel ”这个函数:
def classText_to_classLabel(row_label):if row_label == 'alien_face':return 1elif row_label == 'humen_face':return 2else:return None
所以返回None,肯定是我的标签写错了,查看发现果然是“human_face”,在标签映射函数中写成了“humen_face”.修改函数定义后,解决。
所以程序bug一般最难的不是逻辑问题,是拼写错误 哭笑脸。。
转自:
生成tfrecords时报错:TypeError: None has type NoneType, but expected one of: int, long