【发布时间】:2021-05-19 14:55:37
【问题描述】:
我正在尝试使用我自己的模型来关注 GradCam Tutorial。这是它的架构:
import tensorflow as tf
from tensorflow import keras as K
import numpy as np
class CNNModel(K.Model):
def __init__(self):
super(CNNModel, self).__init__()
self.base = K.applications.EfficientNetB1(input_shape=(224, 224, 12),
include_top=False,
weights=None)
self.pool = K.layers.GlobalAveragePooling2D()
self.drop1 = K.layers.Dropout(0.25)
self.dense1 = K.layers.Dense(16, activation='relu')
self.drop2 = K.layers.Dropout(0.25)
self.out = K.layers.Dense(1, activation='sigmoid')
def call(self, x, training=None, **kwargs):
x = self.base(x)
x = self.pool(x)
x = self.drop1(x)
x = self.dense1(x)
x = self.drop2(x)
x = self.out(x)
return x
model = CNNModel()
model.build(input_shape=(None, 224, 224, 12))
我需要得到最后一个卷积层,所以我从基础 (EfficientNet) 模型中得到一个:
last_conv_layer_name = list(filter(lambda x: isinstance(x, tf.keras.layers.Conv2D), model.base.layers))[-1].name
然后我尝试在此基础上制作一个 2 输出模型,就像在教程中一样。
grad_model = tf.keras.models.Model(
[model.base.inputs], [model.base.get_layer(last_conv_layer_name).output, model.output]
)
我明白了:
AttributeError: Layer cnn_model 没有入站节点
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning