【问题标题】:AttributeError: 'TensorSliceDataset' object has no attribute 'get_shape'AttributeError:“TensorSliceDataset”对象没有属性“get_shape”
【发布时间】:2021-06-24 23:09:07
【问题描述】:

我正在尝试使用数据集将图像加载到模型中。但是,我不断收到一个错误,即我的张量切片没有 get_shape() 属性。我已经确认他们不会尝试在我的代码中调用它。我做错了什么?

我正在使用: Anaconda 上的 Spyder 4.1.5 | Keras 2.3.1 | TensorFlow 2.1.0

# load dataset
dataset = h5py.File('3dshapes.h5', 'r')
print(dataset.keys())
images = dataset['images']  # array shape [480000,64,64,3], uint8 in range(256)
labels = dataset['labels']  # array shape [480000,6], float64

train_dataset = tf.data.Dataset.from_tensor_slices((images[1:10], labels[1:10]))
test_dataset = tf.data.Dataset.from_tensor_slices((images[10:20], labels[10:20])) 

print("train_dataset", train_dataset)
print("test_dataset", test_dataset)

train_dataset

test_dataset

文件“C:\用户\管理 User.conda\envs\Keras\lib\site-packages\tensorflow_core\python\keras\layers\convolutional.py", 第 192 行,通话中 call_input_shape = 输入.get_shape()

AttributeError: 'TensorSliceDataset' 对象没有属性 'get_shape'

【问题讨论】:

    标签: python keras tensorflow2.0 spyder tensorflow-datasets


    【解决方案1】:

    原来我只需要在 Anaconda 上设置一个新的 Python 环境并安装 Tensorflow 和 Keras。我现有的环境已经用这些设置好了,但是其他各种帖子都提到这样做会有所帮助,而且确实如此。

    【讨论】:

      猜你喜欢
      • 2020-08-02
      • 2020-05-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2021-04-19
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多