,python,tensorflow,keras,deep-learning,convolutional-neural-network"/>

首页 > 解决方案 > ValueError:使用不是符号张量的输入调用了层leaky_re_lu_1。收货类型:

问题描述

我想将卷积的值保存在变量 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)

标签: pythontensorflowkerasdeep-learningconvolutional-neural-network

解决方案


您正在混合使用 KerasSequentialFunctionalAPI。

带有SequentialAPI 的代码:

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

带有FunctionalAPI 的代码:

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)

推荐阅读