Keras出现了下面的错误:

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

原因是使用了Keras backend的reshape操作:

x = K.reshape(x, (num_pictures, 32, 32, 512))

但是Keras backend并不是一个Layer,于是出现了上面的错误.解决的方法是使用Lambda,Lambda用于定义一个Layer,其中没有需要学习的变量,只是对Tensor进行一些操作.先定义一个reshape的函数:

def reshape_tensor(x, shape):
    return K.reshape(x, shape);

然后再调用这个函数:

x = Lambda(reshape_tensor, arguments={'shape': (num_pictures, 32, 32, 512)})(x)

这样就不会出错了.

相关文章:

  • 2021-12-22
  • 2021-10-23
  • 2021-10-16
  • 2021-07-19
  • 2021-11-06
  • 2021-11-27
  • 2022-12-23
猜你喜欢
  • 2021-06-02
  • 2022-12-23
  • 2021-10-26
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
相关资源
相似解决方案