Maskrcnn中resnet50改为resnet34「建议收藏」

Maskrcnn中resnet50改为resnet34「建议收藏」因需要训练的数据集并不复杂,resnet50的结构有点冗余,于是就把maskrcnn的backbone从resnet50改为resnet34结构。找到model文件,将resnet50部分代码做一定的修改,就可以得到resnet34的相关代码下面是相关代码:##con_block修改为conv_block0并添加到model文件中defconv_block0(input_tensor…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

找到很多关于maskrcnn具体用法的代码,但是全是基于resnet50/101的,因需要训练的数据集并不复杂,resnet50的结构有点冗余,于是就把maskrcnn的backbone从resnet50改为resnet34结构。
找到model文件,将resnet50(侵删)部分代码做一定的修改,就可以得到resnet34的相关代码
下面是相关代码:


## con_block修改为conv_block0并添加到model文件中
def conv_block0(input_tensor, kernel_size, filters, stage, block,
               strides, use_bias=True, train_bn=True):
    nb_filter1, nb_filter2 = filters
    conv_name_base = 'res' + str(stage) + block + '_branch'
    bn_name_base = 'bn' + str(stage) + block + '_branch'

    x = KL.Conv2D(nb_filter1, (kernel_size, kernel_size),padding='same',strides=strides,
                  name=conv_name_base + '2a', use_bias=use_bias)(input_tensor)
    x = BatchNorm(name=bn_name_base + '2a')(x, training=train_bn)
    x = KL.Activation('relu')(x)

    x = KL.Conv2D(nb_filter2, (kernel_size, kernel_size),padding='same',
                  name=conv_name_base + '2b', use_bias=use_bias)(x)
    x = BatchNorm(name=bn_name_base + '2b')(x, training=train_bn)

    shortcut = KL.Conv2D(nb_filter2, (1, 1), strides=strides, padding='same',
                         name=conv_name_base + '1', use_bias=use_bias)(input_tensor)
    shortcut = BatchNorm(name=bn_name_base + '1')(shortcut, training=train_bn)

    x = KL.Add()([x,shortcut ])
    x = KL.Activation('relu', name='res' + str(stage) + block + '_out')(x)

    return x
    
## identity_block修改为identity_block0,并添加
def identity_block0(input_tensor, kernel_size, filters,  stage, block,
                   use_bias=True, train_bn=True):
 
    nb_filter1, nb_filter2 = filters
    conv_name_base = 'res' + str(stage) + block + '_branch'
    bn_name_base = 'bn' + str(stage) + block + '_branch'


    x = KL.Conv2D(nb_filter1, (kernel_size, kernel_size),name=conv_name_base + '2a',
                  padding='same',

                  use_bias=use_bias)(input_tensor)
    x = BatchNorm(name=bn_name_base + '2a')(x, training=train_bn)
    x = KL.Activation('relu')(x)


    x = KL.Conv2D(nb_filter2, (kernel_size, kernel_size), name=conv_name_base + '2b',padding='same',

                  use_bias=use_bias)(x)
    x = BatchNorm(name=bn_name_base + '2b')(x, training=train_bn)
    x = KL.Activation('relu', name='res' + str(stage) + block + '_out')(x)

    x = KL.Add()([x, input_tensor])

    return x

# 将resnet_graph改为

def resnet_graph(input_image, architecture, stage5=False, train_bn=True):
    """Build a ResNet graph. architecture: Can be resnet50 or resnet101 stage5: Boolean. If False, stage5 of the network is not created train_bn: Boolean. Train or freeze Batch Norm layers """
    assert architecture in ["resnet34", "resnet50", "resnet101"]
    block_identify = { 
   "resnet34": 0, "resnet50": 1, "resnet101": 1}[architecture]
    # Stage 1
    x = KL.ZeroPadding2D((3, 3))(input_image)
    x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=True)(x)
    x = BatchNorm(name='bn_conv1')(x, training=train_bn)
    x = KL.Activation('relu')(x)
    C1 = x = KL.MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)

    # Stage 2
    if block_identify == 0:
        x = conv_block0(x, 3, [64,64], stage=2, block='a',strides=(1, 1),train_bn=train_bn)
        x = identity_block0(x, 3, [64,64], stage=2, block='b', train_bn=train_bn)
        C2 = x = identity_block0(x, 3, [64,64], stage=2, block='c',train_bn=train_bn)

    else:
        x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), train_bn=train_bn)
        x = identity_block(x, 3, [64, 64, 256], stage=2, block='b',train_bn=train_bn)
        C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c', train_bn=train_bn)

    # Stage 3
    if block_identify == 0:
        x = conv_block0(x, 3, [128,128], stage=3, block='a', strides=(2, 2),train_bn=train_bn)
        x = identity_block0(x, 3, [128,128], stage=3, block='b', train_bn=train_bn)
        x = identity_block0(x, 3, [128,128], stage=3, block='c', train_bn=train_bn)
        C3 = x = identity_block0(x, 3, [128,128], stage=3, block='d', train_bn=train_bn)

    else:
        x = conv_block(x, 3, [128, 128, 512], stage=3, block='a', train_bn=train_bn)
        x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', train_bn=train_bn)
        x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', train_bn=train_bn)
        C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d', train_bn=train_bn)


    # Stage 4
    block_count = { 
   "resnet34": 5, "resnet50": 5, "resnet101": 22}[architecture]
    if block_identify == 0:
        x = conv_block0(x, 3, [256,256], stage=4, block='a', strides=(2, 2),train_bn=train_bn)
        for i in range(block_count):
            x = identity_block0(x, 3, [256,256], stage=4, block=chr(98 + i), train_bn=train_bn)
        C4 = x


    else:
        x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a', train_bn=train_bn)
        for i in range(block_count):
            x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i), train_bn=train_bn)
        C4 = x


    # Stage 5
    if stage5:
        if block_identify == 0:
            x = conv_block0(x, 3, [512,512], stage=5, block='a', strides=(2, 2),train_bn=train_bn)
            x = identity_block0(x, 3, [512,512], stage=5, block='b', train_bn=train_bn)
            C5 = x = identity_block0(x, 3, [512,512], stage=5, block='c', train_bn=train_bn)

        else:
            x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a', train_bn=train_bn)
            x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', train_bn=train_bn)
            C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', train_bn=train_bn)

    else:
        C5 = None

    return [C1, C2, C3, C4, C5]




注:
1.初始化权重时我使用的是
https://github.com/qubvel/classification_models/releases/download/0.0.1/resnet34_imagenet_1000.h5
2.compute_backbone_shapes中也要加入resnet34

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185483.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • sql server2000数据库置疑_数据库置疑什么原因

    sql server2000数据库置疑_数据库置疑什么原因搜索热词先分离数据库企业管理器–右键suspect的数据库–所有任务–分离数据库然后备份你的suspect数据库的文件,再按下面的步骤处理:1.新建一个同名的数据库2.再停掉sqlserver3.用suspect数据库的文件覆盖掉这个新建的同名数据库4.再重启sqlserver5.此时打开企业管理器时新建的同名数据库会出现置疑,先不管,执行下面的语句(注意修改其中的数据库名)USEMA…

    2022年8月20日
    8
  • 我裂开了,教给他如何搭建和使用代理服务器,他居然用来做这么不正经的事(爬虫,代理ip)[通俗易懂]

    我裂开了,教给他如何搭建和使用代理服务器,他居然用来做这么不正经的事(爬虫,代理ip)

    2022年2月21日
    83
  • axurerp8授权码最新_ue注册码

    axurerp8授权码最新_ue注册码Licensee:UniversityofScienceandTechnologyofChina(CLASSROOM)Key:DTXRAnPn1P65Rt0xB4eTQ+4bF5IUF0gu0X9XBEUhM4QxY0DRFJxYEmgh4nyh7RtLLicensee:IloveyouAxureKey:UChpuxwbDW6eAIaAf9UujEFSBwN3vpEz9snHv…

    2025年5月27日
    2
  • 【转】Matlab axis用法

    【转】Matlab axis用法Matlabaxis用法转自:http://blog.sina.com.cn/s/blog_b26a90750101kxdx.htmlaxisoff;%去掉坐标轴axistight;%紧坐标轴axisequal;%等比坐标轴axis([-0.1,8.1,-1.1,1.1]);%坐标轴的显示范围%gca:gca,h=figur…

    2022年5月29日
    37
  • 2020爱分析·智能通讯云厂商全景报告[通俗易懂]

    2020爱分析·智能通讯云厂商全景报告[通俗易懂]报告摘要企业面临业务增长的压力,通讯能力建设成为对内提升运营效率,对外提升产品竞争力和客户体验的重要手段,通讯云的场景应用正在加速渗透。基于对国内各行业甲方企业的调研,爱分析认为智能通讯云应用呈现以下趋势:•在提高内部运营效率方面,企业需要通过强化统一通讯能力,及提高办公智能化的方式实现;•对于企业的客服部门或呼叫中心而言,跑马圈地的时代已经过去,随着企业营销与服务渠道多元化,重心在促进营销转化与提升客户体验;•针对各行业的不同业务场景,通讯能力不仅是音视频交互工具的基础,还需..

    2022年5月18日
    49
  • VS 环境使用MySQL Connector C 6.1 连接数据库

    VS 环境使用MySQL Connector C 6.1 连接数据库下载MySQLConnector/C,根据你的系统版本选择下载ZIPARCHIVE,下载链接 配置附加目录和库目录 项目–>属性–>配置属性–>VC++目录-包含目录中加入mysqlConnectC文件的include目录(根据自己的目录设置,此处测试使用了绝对路径) C:\Users\kelvin\Downloads\mysql-connector-c-…

    2022年7月15日
    16

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号