gpt4 book ai didi

python - 属性错误 : 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'decode'

转载 作者:行者123 更新时间:2023-12-03 17:29:52 25 4
gpt4 key购买 nike

我在 python 3.7、Ubuntu 16.04 上使用 tensorflow。抛出上述错误的代码写在下面。它基于以下code .我在 tensorflow 1.13 和 2.0.0-beta1 上都收到此错误

我有一个数据集文件夹,其中包含数百万个形式(图像、时间序列)的数据对。时间序列采用 numpy 格式。我想使用 np.load() 函数来加载数据。但是文件名是字符串张量格式。问题是 np.load() 不接受 tensorflow.python.framework.ops.EagerTensor

import tensorflow as tf
import numpy as np
import imageio

#tf.enable_eager_execution() # use this line if using tensorflow 1.13

imageio.imwrite('data.jpg', np.random.rand(256,256,3))
np.save('data.npy',np.ones(1024))

def load(image_file,timeseries_file):
image = tf.io.read_file(image_file)
image = tf.image.decode_jpeg(image)
timeseries = np.load(timeseries_file.decode())
timeseries = tf.convert_to_tensor(timeseries, np.float32)
image = tf.cast(image, tf.float32)
timeseries = tf.cast(timeseries, tf.float32)
return image, timeseries

image_files = ['data.jpg']
timeseries_files = ['data.npy']
train_dataset = tf.data.Dataset.from_tensor_slices((image_files, timeseries_files))
train_dataset = train_dataset.map(
lambda image_file, timeseries_file: tuple(tf.py_function(
load, [image_file, timeseries_file], [tf.float32, tf.float32])))
for x in train_dataset.take(1):
print(x)

最佳答案

请用

import tensorflow.compat.v1 as tf 
tf.disable_v2_behavior()

关于python - 属性错误 : 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'decode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56673915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com