生成tfrecords时报错:TypeError: None has type NoneType, but expected one of: int, long

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

解决过程:
报错中提示返回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 1
    elif row_label == 'humen_face':
        return 2
    else:
        return None

所以返回None,肯定是我的标签写错了,查看发现果然是“human_face”,在标签映射函数中写成了“humen_face”.修改函数定义后,解决。

所以程序bug一般最难的不是逻辑问题,是拼写错误 哭笑脸。。

你可能感兴趣的:(TensorFlow,AI,tfrecords,tensorflow,object,detection)