我想用TFRecords
爲celeba face dataset。 celeba人臉數據有5個地標位置,每個圖像有40個二進制屬性註釋。對於多任務使用張量流TFRecords數據集
TFRecords
只能給一個標籤。但我想將所有這些標籤保存在TFRecords中。 如何在tensorflow中做到這一點?
我的解決辦法是: 我用this創建TFRecords
文件。 然後,我將celeba屬性文件轉換爲.csv
並通過_dataset = pd.read_csv("./List_attr_celeba.csv")
讀取它。
然後用_dataset["path"] = './img_align_celeba/' + _dataset["name"]
添加它的路徑。 (我用對齊圖像在img_align_celeba
文件夾中)。
首先,然後我使用的功能labels = _dataset.ix[:,1:11].as_matrix()
。
在代碼:
example = tf.train.Example(features=tf.train.Features(feature={ 'height': _int64_feature(rows), 'width': _int64_feature(cols), 'depth': _int64_feature(depth), 'label': _int64_feature(int(labels[index])), 'image_raw': _bytes_feature(image_raw)}))
標籤必須'(<class 'int'>,)
,但labels[index]
具有類型<class 'numpy.ndarray'>
。
因此,我改變:
example = tf.train.Example(features=tf.train.Features(feature={ 'height': _int64_feature(rows), 'width': _int64_feature(cols), 'depth': _int64_feature(depth), 'label': _int64_feature(labels[index].tolist()), 'image_raw': _bytes_feature(image_bytes)})) writer.write(example.SerializeToString())
和:
def _int64_feature(value): if type(value)!= list: value = [value] return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
我的問題是,我用'numpy' 'array'。但是我對'labels [index]'使用'tolist()'函數,並將numpy.int32轉換爲int。 – Tavakoli
這聽起來不錯。你能否詳細說明/澄清問題所在? –
我添加它的問題。 – Tavakoli