AttributeError: ‘tuple‘ object has no attribute ‘shape‘

AttributeError: ‘tuple’ object has no attribute ‘shape’

在将keras代码改为tensorflow2代码的时候报了如下错误

 AttributeError: 'tuple' object has no attribute 'shape'

经过调查发现,损失函数写错了
原来的是这样

model.compile(loss=['binary_crossentropy'],
              optimizer=optimizers.Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, epsilon=1e-08), metrics=['accuracy'],
              )

改成了这样

model.compile(optimizer=optimizers.Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, epsilon=1e-08),
loss=losses.BinaryCrossentropy(),
metrics=[metrics.Accuracy()])

然后就不报错啦!
每个人遇到的问题不一样,希望对你有所帮助。

你可能感兴趣的:(keras,深度学习,tensorflow)