Tensorflow 获取类型错误:为图像输入创建TFR记录时

Tensorflow 获取类型错误:为图像输入创建TFR记录时,tensorflow,tfrecord,Tensorflow,Tfrecord,为图像输入创建TFR记录:如下所示 char_ids_padded, char_ids_unpadded = encode_utf8_string(text) print("char_ids_padded:"+str(char_ids_padded)) print("char_ids_unpadded:"+str(char_ids_unpadded)) tf_example = tf.train.Example(features=t

为图像输入创建TFR记录:如下所示

        char_ids_padded, char_ids_unpadded = encode_utf8_string(text)
        print("char_ids_padded:"+str(char_ids_padded))
        print("char_ids_unpadded:"+str(char_ids_unpadded))
        tf_example = tf.train.Example(features=tf.train.Features(feature={
            'image/format': _bytes_feature(b'png'),
            'image/encoded': _bytes_feature(image.tostring()),
            'image/class': _int64_feature(char_ids_padded),
            'image/unpadded_class': _int64_feature(char_ids_unpadded),
            'height': _int64_feature(image.shape[0]),
            'width': _int64_feature(image.shape[1]),
            'orig_width': _int64_feature(image.shape[1]/num_of_views),
            'image/text': _bytes_feature(text)
            }))


def _int64_feature(value):
  return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))

def _bytes_feature(value):
  return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
添加字符标识的输出,字符标识的输出,如下所示:

字符ID填充:[47,13,16,13,16,16,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

char_ids_unpadded:[47,13,16,13,16,16,52]


注意:填充的字符为列表格式,类型为int,仍然使用tf.train.Features进行映射,错误为TypeError:[47、13、16、13、13、13、16、16、52、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0]具有“类“列表”类型,但应为以下类型之一:(“类“int”)

您已经将一个列表传递给了
tf.train.Int64List
,因此不需要创建包含
\u int64\u feature
参数的新列表。也就是说,你应该尝试改变

tf.train.Int64List(value=[value])

\u int64\u功能
功能中

当我运行以下代码时,它可以工作:

def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=value))

char_ids_padded = [47, 13, 16, 13, 16, 16, 16, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
tf_example = tf.train.Example(features=tf.train.Features(feature={
     'image/class': _int64_feature(char_ids_padded),
}))

我尝试给出tf.train.Int64List(value=value),但仍然得到相同的错误,我更新了答案。当你执行那段代码时,它对你有用吗?对不起,这是我的错误,它现在可以工作了。。谢谢
def _int64_feature(value):
    return tf.train.Feature(int64_list=tf.train.Int64List(value=value))

char_ids_padded = [47, 13, 16, 13, 16, 16, 16, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
tf_example = tf.train.Example(features=tf.train.Features(feature={
     'image/class': _int64_feature(char_ids_padded),
}))