我正在尝试
将一个numpy n维数组作为一串位保存到* .bin文件中。
使用tf.FixedLengthRecordReader
使用tf.decode_raw
这是一项相当标准的操作,无数次,无数在线示例。我试过在tensorflow示例模式中完成的示例行复制行。 (Found here)
下面你看我的尝试。在我尝试评估record_bytes
时,整个过程都会挂起。我已多次重写代码,所以我不确定我搞砸了。
在尝试调试它方面。我确信二进制文件正确,因为我可以使用python方法open()
正确打开和读取文件的内容
不确定如何调试代码的张量流部分。
import numpy as np
import scipy.io
from array import array
import tensorflow as tf
# Generate File
array = np.array([[[1, 2, 3, 3], [4, 5, 6, 6]], [[10, 20, 30, 30], [40, 50, 60, 60]],[[2, 4, 8, 8],[16, 32, 64, 64]]])
output_file = open('temp_file.bin', 'wb')
array.astype('uint8').tofile(output_file)
print(array.shape)
output_file.close()
# Attempt to read file
with tf.Session():
num_bytes = 3*2*4
reader = tf.FixedLengthRecordReader(record_bytes=num_bytes)
filenames = ['temp_file.bin']
for f in filenames:
if not tf.gfile.Exists(f):
raise ValueError('Failed to find file: ' + f)
filename_queue = tf.train.string_input_producer(filenames)
key, value = reader.read(filename_queue)
record_bytes = tf.decode_raw(value, tf.uint8)
print(record_bytes.eval())