2016-12-26 61 views
2

我想用TFRecordsceleba 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))

回答

0

我想每個你寫的記錄是由您來定義原緩衝區,您可以包括任何你需要在原型緩衝區中。

下面是一個例子原緩衝區,我相信你可以重複使用,只要你想,每個標籤作爲一個單獨的功能,包括多張標籤:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/how_tos/reading_data/convert_to_records.py#L66 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/example/example.proto#L88 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/example/feature.proto

+0

我的問題是,我用'numpy' 'array'。但是我對'labels [index]'使用'tolist()'函數,並將numpy.int32轉換爲int。 – Tavakoli

+0

這聽起來不錯。你能否詳細說明/澄清問題所在? –

+0

我添加它的問題。 – Tavakoli