Tensorflow2.0 keras InceptionResNetV2代码实现

本文档介绍了如何使用Tensorflow2.0的keras搭建InceptionResNetV2模型,包括迁移学习的使用,详细解析了InceptionRes模块的各个组成部分如Stem,A、B、C模块以及Reduction A和B。通过自编代码,最终构建了完整的Inception-ResNet网络,并与Keras预训练模型进行了效果对比。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

模型介绍请参看:博文
keras搭建深度学习模型的若干方法:博文

在这里插入图片描述
出处:Google AI
在这里插入图片描述

迁移学习

首先还是看看标准答案

import  tensorflow as tf
from    tensorflow import keras

base_model = keras.applications.InceptionResNetV2(weights='imagenet')
base_model.summary()

在这里插入图片描述
这个summary()是相当的长了。

自编代码

定义卷积单元

def conv2d_cell(x, nbfilter, filtersz, strides=1, pad='same', act=True, name=None):

    x = Conv2D(nbfilter, filtersz, strides, padding=pad, use_bias=False, data_format='channels_last', name=name+'conv2d')(x) #use_bias
    x = BatchNormalization(axis=3, scale=False, name=name+'conv2dbn')(x)    #axis

    if act:
        x = Activation('relu', name=name+'conv2dact')(x)

    return x

Stem模块

在这里插入图片描述

def stem_block(x, name=None):

    x = conv2d_cell(x, 32, 3, 2, 'valid', True, name=name+'conv1')
    x = conv2d_cell(x, 32, 3, 1, 'valid', True, name=name+'conv2')
    x = conv2d_cell(x, 64, 3, 1, 'same', True, name=name+'conv3')

    x_11 = MaxPooling2D(3, strides=2, padding='valid', name=name+'_branch11_maxpool')(x)
    x_12 = conv2d_cell(x, 64, 3, 2, 'valid', True, name=name+'_branch12')

    x = Concatenate(axis =3, name=name+'concat_1')([x_11, x_12])

    x_21 = conv2d_cell(x, 64, 1, 1, 'same', True, name=name+'_branch211')
    x_21 = conv2d_cell(x_21, 64, [1,7], 1, 'same', True, name=name+'_branch212')
    x_21 = conv2d_cell(x_21, 64, [7,1], 1, 'same', True, name=name+'_branch213')
    x_21 = conv2d_cell(x_21, 96, 3, 1, 'valid', True, name=name+'_branch214')

    x_22 = conv2d_cell(x, 64, 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值