python - 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)
解决方案
您正在混合使用 KerasSequential
和Functional
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))
带有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)
推荐阅读
- reactjs - 接口不匹配数据
- image - 从 react-native expo 上传的图片太大且质量太差
- apache - 我想在文件夹 ./project/projects/my-project/index.html 中查看 url /project/my-project/
- swiftui - 如何在 SwiftUI 中将图像与文本对齐
- azure - 在 Azure 数据工厂中更改数据类型
- kubernetes - 将 k8s secret 与部署集成
- c# - 如何确保最佳参数匹配与 ILogging 接口一起用于异常日志记录
- javascript - 如何在javascript中实时乘法
- javascript - D&D 风格的随机机会结果与按钮单击上的 if/then 语句 - 老师试图为课堂活动
- javascript - 使用带有输入的 react-router-dom