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