ValueError:使用不是符号张量的输入调用图层leaky_re_lu_1。收到类型:<class'keras.layers.convolutional.conv3d'=“”>

时间:2018-06-16 13:10:50

标签: python tensorflow keras deep-learning convolutional-neural-network

我想在变量conv1中保存卷积的值,然后在泄漏的relu激活函数中应用conv1的值。

错误:

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)

1 个答案:

答案 0 :(得分:1)

您正在混合使用Keras SequentialFunctional API。

代码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))

代码Sequential 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)