tensorflow2.0 keras 迁移学习 删除预训练模型的最后一层(layer)

Sequential model

方法一、

返回原模型(不包含最后一层)的拷贝

new_model = tf.keras.models.Sequential(base_model.layers[:-1])

方法二、

原地删除原模型的最后一层

base_model._layers.pop()

函数式 API

方法三、

不改动原模型,在采用函数式API构建新模型时,将原模型的倒数第二层的输出向量拼接至新层

x = base_model.layers[-2].output

 

posted on 2021-06-28 15:51  tianyaDream  阅读(1346)  评论(0编辑  收藏  举报

导航