0
的尺寸我建立了一個模型來培訓TensorFlow卷積的自動編碼。我跟着instructions on Reading Data from the TF documentation在我自己的尺寸的圖像讀取233 X 233 X 3.下面是改編自這些說明我convert_to()函數:TensorFlow tfrecords:toString()方法改變圖像
def convert_to(images, name):
"""Converts a dataset to tfrecords."""
num_examples = images.shape[0]
rows = images.shape[1]
cols = images.shape[2]
depth = images.shape[3]
filename = os.path.join(FLAGS.tmp_dir, name + '.tfrecords')
print('Writing', filename)
writer = tf.python_io.TFRecordWriter(filename)
for index in range(num_examples):
print(images[index].size)
image_raw = images[index].tostring()
print(len(image_raw))
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(rows),
'width': _int64_feature(cols),
'depth': _int64_feature(depth),
'image_raw': _bytes_feature(image_raw)}))
writer.write(example.SerializeToString())
writer.close()
當我的開始打印圖像的大小for循環中,大小爲162867,但是當我的ToString()行後打印,尺寸爲1302936.這會導致因爲該模型認爲我的輸入爲8X它應該是什麼樣的道路問題。將示例中的'image_raw'條目更改爲_int64_feature(image_raw)還是更改我將其轉換爲字符串的方式更好?
或者,問題可能是在我的read_and_decode()函數,例如該字符串未正確解碼或該示例未被解析......?
def read_and_decode(self, filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
features={
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64),
'image_raw': tf.FixedLenFeature([], tf.string)
})
# Convert from a scalar string tensor to a uint8 tensor
image = tf.decode_raw(features['image_raw'], tf.uint8)
# Reshape into a 233 x 233 x 3 image and apply distortions
image = tf.reshape(image, (self.input_rows, self.input_cols, self.num_filters))
image = data_sets.normalize(image)
image = data_sets.apply_augmentation(image)
return image
謝謝!
你說得對,我沒有真正需要使用set_shape(),所以我把它改爲只使用重塑()。但是我找出問題出在哪裏,並編輯了這個問題來反映這個問題。如果你知道解決這個問題的正確方法,很樂意聽到你的想法。謝謝! – hannahrae