0

我使用微调。如何查看和访问卷积基础内所有层的激活?

conv_base = VGG16(weights='imagenet',
              include_top=False,
              input_shape=(inp_img_h, inp_img_w, 3))

def create_functional_model():
   inp = Input(shape=(inp_img_h, inp_img_w, 3))
   model = conv_base(inp)
   model = Flatten()(model)
   model = Dense(256, activation='relu')(model)
   outp = Dense(1, activation='sigmoid')(model)
   return Model(inputs=inp, outputs=outp)

model = create_functional_model()
model.summary()

模型摘要是

Layer (type)                 Output Shape              Param #   
=================================================================
vgg16 (Functional)           (None, 7, 7, 512)         14714688  
_________________________________________________________________
flatten_2 (Flatten)          (None, 25088)             0         
_________________________________________________________________
dense_4 (Dense)              (None, 256)               6422784   
_________________________________________________________________
dense_5 (Dense)              (None, 1)                 257       
=================================================================
Total params: 21,137,729
Trainable params: 21,137,729
Non-trainable params: 0
_________________________________________________________________

conv_base因此,无法访问内部的级别。

4

1 回答 1

0

正如@Frightera 在评论中所说,您可以通过以下方式访问基本模型摘要:

model.layers[0].summary()

如果你想访问其层的激活函数,你可以试试这个:

print(model.layers[0].layers[index_of_layer].activation)
#or
print(model.layers[0].get_layer("name_of_layer").activation)
于 2021-10-08T21:32:08.333 回答