搭建inceptionV3加载imagenet预训练权重实现迁移学习

from tensorflow.keras.applications.inception_v3 import InceptionV3
base_model = InceptionV3(weights='imagenet', include_top=False)
# x = base_model.output
# predictions = Dense(7, activation='softmax')(x)
# model = Model(inputs=base_model.input, outputs=predictions)
# 添加自定义分类层
x = base_model.output
x = tf.keras.layers.GlobalAveragePooling2D()(x)
x = tf.keras.layers.Dense(1024, activation='relu')(x)
predictions = tf.keras.layers.Dense(7, activation='softmax')(x)

model = tf.keras.Model(inputs=base_model.input, outputs=predictions)
print('---------------------------------------------模型搭建--------------------------------------------')
# model = InceptionV3(weights='imagenet')
# model = GoogLeNet(im_height=224,im_width=224,class_num=7,aux_logits=True)  # 实例化模型
model.build((32,299,299,3))
model.summary()

# 编译模型
model.compile(
    optimizer='adam',
    loss='categorical_crossentropy',
    metrics=['accuracy']
)

history = model.fit(
    train_dataset,
    epochs=1000,
    validation_data=val_dataset
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值