ValueError: Layer leaky_re_lu_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.convolutional.Conv3D'>

ValueError: Layer leaky_re_lu_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.convolutional.Conv3D'>

我想将卷积的值保存在一个变量conv1中,然后将conv1的值应用到leaky relu激活函数中。

错误:

ValueError: Layer leaky_re_lu_1 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.convolutional.Conv3D'>. Full input: [<keras.layers.convolutional.Conv3D object at 0x7fc6312abe10>]. All inputs to the layer should be tensors.

代码:

model = Sequential()

conv1 = Conv3D(16, kernel_size=(3, 3, 3), input_shape=(
    X.shape[1:]), border_mode='same')
conv2 = (LeakyReLU(alpha=.001))(conv1)

你正在混合 Keras Sequential and Functional APIs.

代码 Sequential API:

from keras.models import Sequential
from keras.layers import Conv3D, LeakyReLU

model = Sequential()
model.add(Conv3D(16, kernel_size=(3, 3, 3), input_shape=(X.shape[1:]), border_mode='same')
model.add(LeakyReLU(alpha=.001))

代码 Functional API:

from keras.models import Model
from keras.layers import Conv3D, LeakyReLU, Input

inputs = Input(shape=X.shape[1:])
conv1 = Conv3D(16, kernel_size=(3, 3, 3), border_mode='same')(inputs)
relu1 = LeakyReLU(alpha=.001)(conv1)
model = Model(inputs=inputs, outputs=relu1)