0
您好我想为图像和它们的一个热门阵列标签创建一个tfrecord.Im能达到它的图像,但不是标签。我提到这个SOF link,但得到相同的错误。下面是我的代码。无法为图像标签创建张量流tfrecord
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]))
for i in range(len(train_addrs)):
print('reading image no {0} : and image address {1}'.format(i,train_addrs[i]))
img = load_image(train_addrs[i])#loading the preprocessed image
label = train_labels[i]#loading associated one-hot array
print('label is ',label) #array([0, 1]) of type uint8 ,I tried with int64,int32 also;but no use
feature = {'train/label':_int64_feature(label),
'train/image':_bytes_feature(tf.compat.as_bytes(img.tostring())) #this part works
}
example = tf.train.Example(features=tf.train.Features(feature=feature))
serToString = example.SerializeToString()
writer.write(serToString)
当我执行该代码,即时得到下面的错误。
TypeError: array([0, 1]) has type <type 'numpy.ndarray'>, but expected one of: (<type 'int'>, <type 'long'>)
我不知道我哪里错了?任何帮助将是非常有用的。
感谢您的回复Ishant。但是在上面的链接中,Steven已经通过了一个列表,看起来似乎是这样吗? – george
是的!您需要修改您的函数,该函数,看到我更新的答案。 –
感谢ü非常ishant..could你喂养的数据tensorflow管道培训提出了一些教程?; – george