Type Error: unhashable type: ‘ Dimension‘ 和 ‘Tensor‘ object has no attribute ‘_keras_history‘

在使用Keras构建深度学习模型时遇到'Type Error: unhashable type: 'Dimension''和'AttributeError: 'Tensor' object has no attribute '_keras_history''的错误。错误源于Keras接口与Tensor数据类型的不兼容以及使用非Keras函数。解决方案包括避免使用tf.one_hot,确保所有操作都是Keras兼容的,并将TensorFlow操作封装在自定义层中。
摘要由CSDN通过智能技术生成

问题描述

在用 Keras 构建复杂的网络的过程中,报错
问题1:Type Error: unhashable type: ’ Dimension’
问题2:AttributeError: ‘Tensor’ object has no attribute ‘_keras_history’
参考链接:
05_keras入门多输入多输出模型(上)
github上此问题的讨论组

首先展示我的错误代码

train.py 部分代码

(train_x, train_y), (test_x, test_y) = datasets.cifar10.load_data()
train_x = train_x / 255.0
test_x = test_x / 255.0
train_y = train_y.flatten()
test_y = test_y.flatten()
train_y = tf.one_hot(train_y, depth=10)# raise error place, erorr 1
test_y = tf.one_hot(test_y, depth=10)# raise error place
print(train_x.shape, train_y.shape, test_x.shape, test_y.shape)

model_input = Input(shape=(32, 32, 3))
model = LENET(model_input, Convway=convway, Poolingway=poolingway)
model.summary()
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
history = model.fit(x=train_x, y=train_y, batch_size=50, verbose=1</
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值