简体   繁体   English

没有入站节点-Keras CNN模型

[英]No Inbound Nodes - Keras CNN Model

I had trained a CNN model in keras with the following structure 我已经按照以下结构在喀拉拉邦训练了CNN模型

model_11 = Sequential()

#Convolutional Layers
model_11.add(Reshape((55, 1)))
model_11.add(Conv1D(50, kernel_size=5, strides=1, padding="same", activation = 'relu'))
model_11.add(Conv1D(24, kernel_size=4, strides=5, padding="same", activation = 'relu'))
model_11.add(Conv1D(23, kernel_size=2, strides=1, padding="same", activation = 'relu'))

#Dense Layers
model_11.add(Flatten())
model_11.add(Dense(units=30, activation='relu'))
model_11.add(Dense(units=15, activation='relu'))

model_11.add(Dense(units=1, activation='sigmoid'))

#Compile model
model_11.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

#Fit the model
model_11.fit(X_train, y_train, epochs=20, batch_size=20)



Now, I tried the following 现在,我尝试了以下

model_11.layers[-3].output



Which gives me the following error 这给我以下错误

AttributeError: Layer dense_40 has no inbound nodes. AttributeError:层density_40没有入站节点。



There are many solutions regarding multiple inbound nodes, but I haven't seen anything so far for no inbound nodes. 关于多个入站节点,有许多解决方案,但是到目前为止,对于没有入站节点,我还没有看到任何东西。 And despite that, the model is working well (binary classification). 尽管如此,该模型仍然运行良好(二进制分类)。

This is because when you define a Sequential without specifying the input shape for the first layer, the computation graph is only created during the fit function, and thus layers' input and output tensors (and thus nodes) are not computed. 这是因为当您在不指定第一层的输入形状的情况下定义Sequential图时,仅在fit函数期间创建了计算图,因此不会计算层的输入和输出张量(因此也将不计算节点)。

If you need to access output tensor of a layer, specify the input shape for the first layer in the sequential model. 如果需要访问层的输出张量,请为顺序模型中的第一层指定输入形状。 Thus the first layer is defined as this: 因此,第一层定义如下:

model_11.add(Reshape((55, 1), input_shape=(55,))

Now model_11.layers[-3].output will return a tensor. 现在model_11.layers[-3].output将返回一个张量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “AttributeError:Layer cnn_model has no inbound nodes”从 Keras GradCam 教程的子类 model 制作 model 时 - "AttributeError: Layer cnn_model has no inbound nodes" when making a model from a subclassed model for Keras GradCam tutorial Keras:CNN模型不是在学习 - Keras: CNN model is not learning 计算与AttributeError匹配的keras模型中的皮尔逊系数:'NoneType'对象没有属性'_inbound_nodes' - Calculating the pearson coefficients in a keras model met with AttributeError: 'NoneType' object has no attribute '_inbound_nodes' AttributeError:层 mnist_model_35 没有入站节点。 Tensorflow keras 子类化 API - AttributeError: Layer mnist_model_35 has no inbound nodes. Tensorflow keras subclassing API tensorflow / keras CNN模型架构 - tensorflow/keras CNN model Architecture CNN model 和 Keras 精度差 - Poor accuracy of CNN model with Keras 无法使用 CNN model 导入 keras - failed to import keras with CNN model Keras中的CNN model条件层 - CNN model conditional layer in Keras 计算 Keras CNN model 的指标 - Calculate Metrics for Keras CNN model 在一个功能模型中合并两个keras顺序模型时出错:AttributeError:'NoneType'对象没有属性'_inbound_nodes' - Error when combine two keras sequential models inside one functional model: AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM