在Tensorflow阅读器中有三个版本。
tf.TFRecordReader,用于读取TFRecord文件tf.FixedLengthRecordReader,用于读取二进制文件tf.TextLineReader,用于读取CSV文件。,但我应该如何读取.mat文件格式?我应该用哪种阅读器?有读取.mat文件的阅读器吗?
Description:目前,我正在制作一个小的CNN模型,用于使用街景房号数据集对住房号进行分类。dataset使用.mat文件格式,.It是一个大型数据集。如果我使用读取机制中的Tensorflow构建来读取数据集,将会很有帮助。但我应该使用哪种阅读器呢?
发布于 2017-10-23 14:06:05
发布于 2019-03-22 20:02:16
如果您不想使用TFRecords,这里有一种方法可以使用tf.py_func获取通过tf.data.Dataset API导入的.mat文件。
def read_mat(filepath):
def _read_mat(filepath):
matfile = sio.loadmat(filepath)
data0 = matfile['data0']
data1 = matfile['data1']
data2 = mat_contents['data2']
shape0 = matfile['data0'].shape
return data0, data1, data2, np.asarray(shape0)
output = tf.py_func(_read_mat, [filepath], [tf.double, tf.uint16, tf.double, tf.int64])
shape = output[3]
data0 = tf.reshape(output[0], shape)
data1 = tf.reshape(output[1], shape)
data2 = tf.reshape(output[2], shape)
return data0, data1, data2
dataset = tf.data.Dataset.list_files('*.mat')
dataset = dataset.map(read_mat, num_parallel_calls=16)
dataset = dataset.repeat(100)
dataset = dataset.batch(8)
dataset = dataset.prefetch(8)
iterator = dataset.make_initializable_iterator()
sess = tf.Session()
sess.run(iterator.initializer)
values = sess.run(iterator.get_next())发布于 2017-10-23 14:36:25
我认为在tensorflow模型中加载数据的更好方法可能是手动将.mat转换为numpy格式。
Numpy非常适合TensorFlow,您可以很容易地找到其他可以帮助您的帖子。
希望它能帮到你!
https://stackoverflow.com/questions/46890387
复制相似问题