[英]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.