简体   繁体   English

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' 对象没有属性 'decode'

[英]AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'decode'

I am using tensorflow on python 3.7, Ubuntu 16.04.我在 python 3.7、Ubuntu 16.04 上使用 tensorflow。 The code which throws the above mentioned error is written below.抛出上述错误的代码写在下面。 It is based on the following code .它基于以下代码 I am getting this error on both tensorflow 1.13 as well as 2.0.0-beta1我在 tensorflow 1.13 和 2.0.0-beta1 上都收到此错误

I have a dataset folder containing millions of data pair of the form (image,timeseries).我有一个数据集文件夹,其中包含数百万个形式(图像、时间序列)的数据对。 The timeseries is in numpy format.时间序列采用 numpy 格式。 I want to use np.load() function to load the data.我想使用 np.load() 函数来加载数据。 But the filename is in string tensor format.但是文件名是字符串张量格式。 The problem is np.load() does not accept tensorflow.python.framework.ops.EagerTensor问题是 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)

Please use请用

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

EagerTensor can be converted to numpy array as: EagerTensor 可以转换为 numpy 数组,如下所示:

tensor.numpy()
# or
np.array(tensor)

So try:所以尝试:

timeseries = np.load(timeseries_file.numpy().decode())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象没有属性 &#39;to_tensor&#39; - AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'to_tensor' AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object 没有属性 'ravel' - AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'ravel' &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象没有属性 &#39;squeeze&#39; - 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'squeeze' 'tensorflow.python.framework.ops.EagerTensor' object 没有属性 '_in_graph_mode' - 'tensorflow.python.framework.ops.EagerTensor' object has no attribute '_in_graph_mode' 类型 &#39;tensorflow.python.framework.ops.EagerTensor&#39; 没有 len() - type 'tensorflow.python.framework.ops.EagerTensor' has no len() 项目分配 Tensorflow 2.0 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object 不支持项目分配 - Item Assignment Tensorflow 2.0 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment TypeError: &#39;tensorflow.python.framework.ops.EagerTensor&#39; 对象不支持项目分配 - TypeError: 'tensorflow.python.framework.ops.EagerTensor' object does not support item assignment 类型错误:<tf.tensor: shape ...> 有类型<class 'tensorflow.python.framework.ops.eagertensor'> ,但预期其中之一:(<class 'int'> ,)</class></class></tf.tensor:> - TypeError: <tf.Tensor: shape ... > has type <class 'tensorflow.python.framework.ops.EagerTensor'>, but expected one of: (<class 'int'>,) AttributeError: 模块“tensorflow.python.framework.ops”没有属性“RegisterShape” - AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape' AttributeError:模块'tensorflow.python.framework.ops'没有属性'_TensorLike' - AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM