使用Lambda解决_inbound_nodes错误

Keras出现了下面的错误:node

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);

而后再调用这个函数:spa

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

这样就不会出错了.code

相关文章
相关标签/搜索