如何将np,load()与张量一起使用?

2024-03-28 21:31:07 发布

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

我想用张量加载numpy文件。所以,我用tf.py_函数(),但它出现在typeerror中。Numpy能处理Tensorflow张量吗?你知道吗

def npload(array):
    return np.load(array)

output = tf.train.slice_input_producer([image_list_LR_tensor, image_list_HR_tensor], shuffle=False, capacity=FLAGS.name_queue_capacity) 
# image_list_LR_tensor : a tensor, list of npy files

 # Reading and decode the images
reader = tf.WholeFileReader(name='image_reader')
image_LR = tf.read_file(output[0])

input_image_LR = tf.py_func(npload, [image_LR], [tf.float32])
input_image_LR = tf.image.convert_image_dtype(input_image_LR, dtype=tf.float32)
# When use tf.py_func()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 0: invalid start byte
         [[{{node load_image/PyFunc_1}}]]

# When use tf.py_fuction()
TypeError: expected str, bytes or os.PathLike object, not tensorflow.python.framework.ops.EagerTensor
         [[{{node load_image/EagerPyFunc}}]]

Tags: namepyimageinputoutputtfloadarray