tensorflow - Tensorflow:访问查看层激活(微调),
问题描述
我使用微调。如何查看和访问卷积基础内所有层的激活?
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
因此,无法访问内部的级别。
解决方案
正如@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)
推荐阅读
- python - 将多个表从 postgres 连接到 python
- excel - 基于一定数量的列/行的范围
- mainframe - 大型机 JCL 按列连接 4 个文件,所有文件具有不同的行数,
- django - Django - 由于表单字段为空,表单返回无效
- google-apps-script - 在 Google 表格宏中插入时间戳
- c - 从 Golang 调用 C 函数
- reactjs - React Typescript:第 0 行:解析错误:无法读取未定义的属性“名称”
- c# - 如何递归地将json文件转换为字典
在 dotnet 核心中 - c# - 如何从 Xamarin MVVMCross 的剃刀视图中正确加载生成的 PDF 中的字体?
- mysql - 如何查找记录是否未链接到任何其他关系?