tfrecord数据报错 InvalidArgumentError: Feature: feature (data type: string) is required but could not

InvalidArgumentError: Feature: feature (data type: string) is required but could not be found.

问题原因: 生成的.tfrecord数据中的key(键值)和你在代码中读取的 key 不匹配导致的。我们在使用不是自己产生的数据时经常会出现这样的错误。既然数据已经生成了,就不可能再去修改数据了,所以将你读取的代码中的键值改成生成时的就OK了

例:我产生报错的原因

生成时:

  feature = {
        'image': _bytes_feature(encoded_jpg),
        'label': _int64_feature(integer_label)
    }

读取时:

  features = {
        'image': tf.FixedLenFeature([], tf.string),
        'target': tf.FixedLenFeature([], tf.int64)
    }

这就很明显了,上面时 label。 下面是 target。所以会报错啦。将下面的target改成上面的label就好啦

即:

  features = {
        'image': tf.FixedLenFeature([], tf.string),
        'label': tf.FixedLenFeature([], tf.int64)
    }

猜你喜欢

转载自blog.csdn.net/qq_41368074/article/details/110691078
今日推荐