shuffleNet_flush privileges

shuffleNet_flush privilegeschannelshuffle:1)利用group,再组间进行深度卷积。优点:1)极大减小计算量(FLOPS)由于每个filter不再是和输入的全部featuremap做卷积,而是仅仅和一个group的featuremap做卷积。缺点:边界效应产生,即某个输出channel仅仅来自输入channel的一小部分细节:一般卷积操作中比如输入fe…

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

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

channel shuffle:

1)利用group ,再组间进行深度卷积。

优点:1)极大减小计算量(FLOPS)

               由于每个filter不再是和输入的全部feature map做卷积,而是仅仅和一个group的feature map做卷积。

 缺点:边界效应产生,即某个输出channel仅仅来自输入channel的一小部分

细节:一般卷积操作中比如输入feature map的数量是N,该卷积层的filter数量是M,那么M个filter中的每一个filter都要和N个feature map的某个区域做卷积,然后相加作为一个卷积的结果。假设你引入group操作,设group为g,那么N个输入feature map就被分成g个group,M个filter就被分成g个group,然后在做卷积操作的时候,第一个group的M/g个filter中的每一个都和第一个group的N/g个输入feature map做卷积得到结果,第二个group同理,直到最后一个group.

2)为了抵消边界效应,提出channel shuffle

这里写图片描述

本质; 即进行GConv2之前,对其输入feature map做一个分配,使得GConv2的每一个group都能卷积输入的所有group的feature map

def _shuffle(x, groups):
    def shuffle_layer(x):
        _, w, h, n = K.int_shape(x)
        nb_chan_per_grp = n // groups

        x = K.reshape(x, (-1, w, h, nb_chan_per_grp, groups))
        x = K.permute_dimensions(x, (0, 1, 2, 4, 3)) # Transpose only grps and chs(按照给定的模式重排一个张量的轴)
        x = K.reshape(x, (-1, w, h, n)
        return x

 

 

附代码:

 

from keras.models import Model
from keras.layers import *
from keras.activations import *
from keras.callbacks import *
import keras.backend as K
from keras.engine.topology import get_source_inputs
count=0
def _info(groups):
    return {
        1: [24, 144, 288, 576],
        2: [24, 200, 400, 800],
        3: [24, 240, 480, 960],
        4: [24, 272, 544, 1088],
        8: [24, 384, 768, 1536]
    }[groups], [None, 3, 7, 3]


def basemodel(input_tensor=None, input_shape=None,groups=8):

    if input_tensor is None:
        img_input = Input(shape=input_shape)
    else:
        if not K.is_keras_tensor(input_tensor):
            img_input = Input(tensor=input_tensor, shape=input_shape)
        else:
            img_input = input_tensor

    bn_axis = 3 if K.image_data_format() == 'channels_last' else 1

    x = Conv2D(24,
               kernel_size=(3, 3),
               strides=2,
               use_bias=False,
               padding='same')(img_input)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = MaxPooling2D(pool_size=(3, 3),
                     strides=2,
                     padding='same',)(x)
    x = Activation('relu',name='pool1')(x)


    channels_list, repeat_list = _info(groups)   #  [24, 200, 400, 800],[None, 3, 7, 3]
   # import pdb;pdb.set_trace()

    for i, (out_channels, repeat) in enumerate(zip(channels_list[1:], repeat_list[1:]), start=1):

        x = _stage(x, groups, channels_list[i-1], out_channels, repeat)


 #8
    if input_tensor is not None:
        inputs = get_source_inputs(input_tensor)
    else:
        inputs = img_input
    model = Model(inputs, x, name='basemodel_dense')

    return model


def _stage(tensor, groups, in_channels, out_channels, repeat):#repeat=repeat_list[1:],[None, 3, 7, 3]
    x = _shufflenet_unit(tensor, groups, in_channels, out_channels, 2) #2

    for _ in range(repeat):
        x = _shufflenet_unit(x, groups, out_channels, out_channels, 1)


    return x

#out_i=[4,12,16]
#(name='stage%s'% k[0])

def _pw_group(tensor, groups, in_channels, out_channels):      #一个组,分通道卷积操作,之后cancat
    """Pointwise grouped convolution."""
    nb_chan_per_grp = in_channels // groups

    pw_convs = []
    for grp in range(groups):
        x = Lambda(lambda x: x[:, :, :, nb_chan_per_grp * grp: nb_chan_per_grp * (grp + 1)])(tensor)
        grp_out_chan = int(out_channels / groups + 0.5)

        pw_convs.append(
            Conv2D(grp_out_chan,
                   kernel_size=(1, 1),
                   padding='same',
                   use_bias=False,
                   strides=1)(x)
        )

    return Concatenate(axis=-1)(pw_convs)


def _shuffle(x, groups):            #通道间的打乱
    def shuffle_layer(x):
        _, w, h, n = K.int_shape(x)
        nb_chan_per_grp = n // groups

        x = K.reshape(x, (-1, w, h, nb_chan_per_grp, groups))
        x = K.permute_dimensions(x, (0, 1, 2, 4, 3)) # Transpose only grps and chs(按照给定的模式重排一个张量的轴)
        x = K.reshape(x, (-1, w, h, n))

        return x

    return Lambda(shuffle_layer)(x)


def _shufflenet_unit(tensor, groups, in_channels, out_channels, strides, shuffle=True, bottleneck=4):
    bottleneck_channels = out_channels // bottleneck

    x = _pw_group(tensor, groups, in_channels, bottleneck_channels)   #深度可分离卷积
    x = BatchNormalization()(x)
    x = Activation('relu')(x)

    if shuffle:
        x = _shuffle(x, groups)         #通道间的打乱

    x = DepthwiseConv2D(kernel_size=(3, 3),             #深度卷积
                        padding='same',
                        use_bias=False,
                        strides=strides)(x)
    x = BatchNormalization()(x)


    x = _pw_group(x, groups, bottleneck_channels,
                  out_channels if strides < 2 else out_channels - in_channels)
    x = BatchNormalization()(x)

    if strides < 2:
        x = Add()([tensor, x])
    else:
        avg = AveragePooling2D(pool_size=(3, 3),
                               strides=2,
                               padding='same')(tensor)

        x = Concatenate(axis=-1)([avg, x])
    global count
    count+=1
    x = Activation('relu',name='stage%s'% count)(x)



    return x



 

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

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

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


相关推荐

  • 网站访问人数太多,怎么才能进入_网址挖掘

    网站访问人数太多,怎么才能进入_网址挖掘老规矩,先上代码:#coding=utf-8importosimportrequestsimporttimefromPILimportImagefromioimportBytesIOfromlxmlimportetree#先定义一个opener函数:defopen_mn_web(url):try:headers=…

    2025年7月5日
    4
  • 再次发布一个jq的下拉框式日期选择插件 dateSelector ~

    再次发布一个jq的下拉框式日期选择插件 dateSelector ~

    2021年7月26日
    64
  • 40个容易上瘾的HTML5网页游戏,总有一款适合你[通俗易懂]

    40个容易上瘾的HTML5网页游戏,总有一款适合你[通俗易懂]我记得姐姐家的孩子在刚刚才学会走路,说话还不能完整的时候就已经能自己用小手点出小游戏的网站来一个人自娱自乐。我一直在想这一代跟着计算机一起茁壮成长的孩子会不会也和美国那一代人一样,出现9岁的黑客和计算机天才。但是并不是信息的成长就能让教育同步。很多时候我们会发现教育在发展的大环境中并没有什么创新的思考。不管怎么说,我们还是需要小盆友们能有足够的想象力。不要被束缚!今天分享的是40个HTML5的网页

    2022年5月24日
    32
  • 数据库分区、分表、分库、分片[通俗易懂]

    数据库分区、分表、分库、分片[通俗易懂]一、分区的概念        数据分区是一种物理数据库的设计技术,它的目的是为了在特定的SQL操作中减少数据读写的总量以缩减响应时间。        分区并不是生成新的数据表,而是将表的数据均衡分摊到不同的硬盘,系统或是不同服务器存储介子中,实际上还是一张表。另外,分区可以做到将表的数据均衡到不同的地方,提高数据检索的效率,降低数据库的频繁IO压力值,分区的优点如下:1、相对于单个文件系统或是硬盘…

    2022年5月3日
    46
  • Oracle安装配置流程

    Oracle安装配置流程

    2022年1月24日
    86
  • 角色权限表怎么设计_用户角色权限在数据库表中怎样实现

    角色权限表怎么设计_用户角色权限在数据库表中怎样实现设计一个灵活、通用、方便的权限管理系统。      在这个系统中,我们需要对系统的所有资源进行权限控制,那么系统中的资源包括哪些呢?我们可以把这些资源简单概括为静态资源(功能操作、数据列)和动态资源(数据),也分别称为对象资源和数据资源,后者是我们在系统设计与实现中的叫法。系统的目标就是对应用系统的所有对象资源和数据资源进行权限控制,比如应用系统的功能菜单、各个界面的按钮、数据显示的列以

    2022年9月1日
    6

发表回复

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

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