如何解码队列中Tensorflow中的pfm文件?

2024-09-29 23:17:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个文件名队列,文件是*.pfm文件。我编写了一个转换函数readPFM(),将*.pfm文件转换为ndarray。在

我想做的是,当一个文件从队列中出列时,我将使用函数将其转换为numpy ndarray。然后它将被输入到图表中。但代码不起作用。在

def disparity(batch_size, path, LR, epochs=2):
    filenames = file_name(path, LR, 'pfm')
    filenames = sorted(filenames)

    filename_queue = tf.train.string_input_producer(filenames, shuffle=False, num_epochs=epochs)
    reader = tf.WholeFileReader()
    key, img_bytes = reader.read(filename_queue)
    disparity, _ = readPFM(img_bytes)

    return tf.train.batch([disparity], batch_size, dynamic_pad=True)

pfm文件read func在这里。在

^{pr2}$

错误消息显示我的函数不能处理张量,因为它只能处理*.pfm文件。在

有什么解决办法吗?在


Tags: 文件path函数size队列tfbatchfilename
1条回答
网友
1楼 · 发布于 2024-09-29 23:17:18

不能像tensorflow那样使用readPFM函数,需要用tf.py_func来包装它。在

# helper function
def decode_pfm(path):
    data, _ = load_pfm(open(path, 'rb'))

    # http://netpbm.sourceforge.net/doc/pfm.html
    # pfm stores the data bottom-to-top, need to reverse
    data = np.flipud(data)
    data = np.expand_dims(data, 2)
    return data

def read_and_decode(path):
    image_decoded = tf.py_func(decode_pfm, [path], tf.float32)

    # py_func does not set the shape, you might need to explictly
    # set it
    image_decoded.set_shape((H, W, channels))

相关问题 更多 >

    热门问题