【发布时间】:2017-07-21 21:10:23
【问题描述】:
以下代码是.mat文件的批处理数据提供者,但运行时出现以下问题:
TypeError: expected str, bytes or os.PathLike object, not FIFOQueue
代码是:
import numpy as np
import tensorflow as tf
from tensorflow.python.framework import ops
from tensorflow.python.framework import dtypes
import h5py
def Reader(filename):
with h5py.File(filename, 'r') as f:
image = np.transpose(np.array(f.get('patch_x'), dtype=np.float32))
label = np.transpose(np.array(f.get('patch_y'), dtype=np.float32))
image = ops.convert_to_tensor(image, dtype=dtypes.float32)
label = ops.convert_to_tensor(label, dtype=dtypes.float32)
return image, label
def Inputs(filenames, batch_size, shuffle=True):
filenames = ops.convert_to_tensor(filenames, dtype=dtypes.string)
filename_queue = tf.train.string_input_producer(filenames, shuffle=shuffle)
image, label = Reader(filename_queue)
image = tf.cast(image, tf.float32)
label = tf.cast(label, tf.float32)
num_preprocess_threads = 4
if shuffle:
image_batch, label_batch = tf.train.shuffle_batch([image, label], batch_size=batch_size, num_threads=num_preprocess_threads, capacity=5*batch_size, min_after_dequeue=2*batch_size)
else:
image_batch, label_batch = tf.train.batch([image, label], batch_size=batch_size, num_threads=num_preprocess_threads, capacity=5*batch_size, min_after_dequeue=2*batch_size)
return image_batch, label_batch
有谁知道如何轻松地将 string 张量转换为 python string?谢谢。
更新 1:
使用filename.dequeue()时,报错信息为:
TypeError: expected str, bytes or os.PathLike object, not Tensor
【问题讨论】:
-
错误出现在哪一行?
-
@Aaron 此行
with h5py.File(filename, 'r') as f:
标签: tensorflow