当前位置: 首页>>代码示例>>Python>>正文


Python tfutils.argscope方法代码示例

本文整理汇总了Python中tensorpack.tfutils.argscope方法的典型用法代码示例。如果您正苦于以下问题:Python tfutils.argscope方法的具体用法?Python tfutils.argscope怎么用?Python tfutils.argscope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorpack.tfutils的用法示例。


在下文中一共展示了tfutils.argscope方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        with argscope([Conv2D, MaxPooling, AvgPooling, GlobalAvgPooling, BatchNorm], data_format=self.data_format), \
             argscope([QuantizedActiv], nbit=self.qa):
            if self.mode == 'vgg':
                return vgg_backbone(image, self.qw)
            elif self.mode == 'alexnet':
                return alexnet_backbone(image, self.qw)
            elif self.mode == 'googlenet':
                return googlenet_backbone(image, self.qw)
            elif self.mode == 'densenet':
                return densenet_backbone(image, self.qw)
            else:
                if self.mode == 'preact':
                    group_func = preresnet_group
                elif self.mode == 'preact_typeA':
                    group_func = preresnet_group_typeA
                else:
                    group_func = resnet_group
                return resnet_backbone(
                    image, self.num_blocks,
                    group_func, self.block_func, self.qw) 
开发者ID:microsoft,项目名称:LQ-Nets,代码行数:23,代码来源:imagenet.py

示例2: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):

        def weight_standardization(v):
            if not self.use_WS:
                return v
            if (not v.name.endswith('/W:0')) or v.shape.ndims != 4:
                return v
            mean, var = tf.nn.moments(v, [0, 1, 2], keep_dims=True)
            v = (v - mean) / (tf.sqrt(var)+ 1e-5)
            return v

        num_blocks = {50: [3, 4, 6, 3], 101: [3, 4, 23, 3]}[self.depth]
        block_func = resnet_bottleneck
        with argscope([Conv2D, MaxPooling, GlobalAvgPooling], data_format=self.data_format), \
                varreplace.remap_variables(weight_standardization):
            return resnet_backbone(
                image, num_blocks, resnet_group, block_func) 
开发者ID:ppwwyyxx,项目名称:GroupNorm-reproduce,代码行数:19,代码来源:imagenet-resnet-gn.py

示例3: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, inputs):
        sc = ghostnet_arg_scope(
            data_format=self.data_format,
            weight_decay=self.weight_decay,
            use_batch_norm=True,
            batch_norm_decay=0.9997,
            batch_norm_epsilon=0.001,
            regularize_depthwise=False)
        with slim.arg_scope(sc):
            with argscope(Conv2D, 
                  kernel_initializer=kernel_initializer):
                with argscope([Conv2D, BatchNorm], data_format=self.data_format):
                    logits, end_points = ghost_net(
                        inputs,
                        dw_code=self.dw_code,
                        ratio_code=self.ratio_code,
                        se=self.se,
                        num_classes=self.num_classes,
                        dropout_keep_prob=self.dropout_keep_prob,
                        min_depth=8,
                        depth_multiplier=self.depth_multiplier,
                        depth=self.depth,
                        conv_defs=None,
                        prediction_fn=tf.contrib.layers.softmax,
                        spatial_squeeze=True,
                        reuse=None,
                        scope=self.scope,
                        global_pool=False)
                    return logits


# =========================================================================== #
# Functional definition.
# =========================================================================== #
# Conv and Bottleneck namedtuple define layers of the GhostNet architecture
# Conv defines 3x3 convolution layers
# stride is the stride of the convolution
# depth is the number of channels or filters in a layer 
开发者ID:huawei-noah,项目名称:ghostnet,代码行数:40,代码来源:ghostnet.py

示例4: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        with argscope([Conv2D, MaxPooling, GlobalAvgPooling, BatchNorm], data_format='NCHW'), \
                argscope(Norm, type=self.norm):
            return resnet_backbone(image, self.num_blocks, resnet_group, resnet_bottleneck) 
开发者ID:tensorpack,项目名称:benchmarks,代码行数:6,代码来源:imagenet-resnet-horovod.py

示例5: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        with argscope([Conv2D, MaxPooling, GlobalAvgPooling, BatchNorm], data_format=self.data_format):
            return resnet_backbone(
                image, self.num_blocks,
                preresnet_group if self.mode == 'preact' else resnet_group, self.block_func) 
开发者ID:qinenergy,项目名称:webvision-2.0-benchmarks,代码行数:7,代码来源:imagenet-resnet.py

示例6: _get_dim

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def _get_dim(x, dim):
    """ Get the dimension value of a 4-tensor.
    Helper for _get_C/H/W.
    get_C,H,W will use argscope to set the default dim.
    Otherwise we assume it is NCHW.
    """
    return x.get_shape().as_list()[dim] 
开发者ID:microsoft,项目名称:petridishnn,代码行数:9,代码来源:common.py

示例7: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        with argscope([Conv2D, MaxPooling, GlobalAvgPooling, BatchNorm], data_format=self.data_format):
            return resnet_backbone(
                image, self.num_blocks,
                preact_group if self.mode == 'preact' else resnet_group, self.block_func) 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:7,代码来源:imagenet-resnet.py

示例8: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):

        with argscope([Conv2D, MaxPooling, AvgPooling, GlobalAvgPooling, BatchNorm], data_format='channels_first'), \
                argscope(Conv2D, use_bias=False):

            group = args.group
            if not args.v2:
                # Copied from the paper
                channels = {
                    3: [240, 480, 960],
                    4: [272, 544, 1088],
                    8: [384, 768, 1536]
                }
                mul = group * 4  # #chan has to be a multiple of this number
                channels = [int(math.ceil(x * args.ratio / mul) * mul)
                            for x in channels[group]]
                # The first channel must be a multiple of group
                first_chan = int(math.ceil(24 * args.ratio / group) * group)
            else:
                # Copied from the paper
                channels = {
                    0.5: [48, 96, 192],
                    1.: [116, 232, 464]
                }[args.ratio]
                first_chan = 24

            logger.info("#Channels: " + str([first_chan] + channels))

            l = Conv2D('conv1', image, first_chan, 3, strides=2, activation=BNReLU)
            l = MaxPooling('pool1', l, 3, 2, padding='SAME')

            l = shufflenet_stage('stage2', l, channels[0], 4, group)
            l = shufflenet_stage('stage3', l, channels[1], 8, group)
            l = shufflenet_stage('stage4', l, channels[2], 4, group)

            if args.v2:
                l = Conv2D('conv5', l, 1024, 1, activation=BNReLU)

            l = GlobalAvgPooling('gap', l)
            logits = FullyConnected('linear', l, 1000)
            return logits 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:43,代码来源:shufflenet.py

示例9: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        with argscope(Conv2D, kernel_initializer=tf.variance_scaling_initializer(scale=2.)), \
                argscope([Conv2D, MaxPooling, BatchNorm], data_format='channels_first'):
            logits = (LinearWrap(image)
                      .apply(convnormrelu, 'conv1_1', 64)
                      .apply(convnormrelu, 'conv1_2', 64)
                      .MaxPooling('pool1', 2)
                      # 112
                      .apply(convnormrelu, 'conv2_1', 128)
                      .apply(convnormrelu, 'conv2_2', 128)
                      .MaxPooling('pool2', 2)
                      # 56
                      .apply(convnormrelu, 'conv3_1', 256)
                      .apply(convnormrelu, 'conv3_2', 256)
                      .apply(convnormrelu, 'conv3_3', 256)
                      .MaxPooling('pool3', 2)
                      # 28
                      .apply(convnormrelu, 'conv4_1', 512)
                      .apply(convnormrelu, 'conv4_2', 512)
                      .apply(convnormrelu, 'conv4_3', 512)
                      .MaxPooling('pool4', 2)
                      # 14
                      .apply(convnormrelu, 'conv5_1', 512)
                      .apply(convnormrelu, 'conv5_2', 512)
                      .apply(convnormrelu, 'conv5_3', 512)
                      .MaxPooling('pool5', 2)
                      # 7
                      .FullyConnected('fc6', 4096,
                                      kernel_initializer=tf.random_normal_initializer(stddev=0.001))
                      .tf.nn.relu(name='fc6_relu')
                      .Dropout('drop0', rate=0.5)
                      .FullyConnected('fc7', 4096,
                                      kernel_initializer=tf.random_normal_initializer(stddev=0.001))
                      .tf.nn.relu(name='fc7_relu')
                      .Dropout('drop1', rate=0.5)
                      .FullyConnected('fc8', 1000,
                                      kernel_initializer=tf.random_normal_initializer(stddev=0.01))())
        add_param_summary(('.*', ['histogram', 'rms']))
        return logits 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:41,代码来源:vgg16.py

示例10: get_logits

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def get_logits(self, image):
        gauss_init = tf.random_normal_initializer(stddev=0.01)
        with argscope(Conv2D,
                      kernel_initializer=tf.variance_scaling_initializer(scale=2.)), \
                argscope([Conv2D, FullyConnected], activation=tf.nn.relu), \
                argscope([Conv2D, MaxPooling], data_format='channels_last'):
            # necessary padding to get 55x55 after conv1
            image = tf.pad(image, [[0, 0], [2, 2], [2, 2], [0, 0]])
            l = Conv2D('conv1', image, filters=96, kernel_size=11, strides=4, padding='VALID')
            # size: 55
            visualize_conv1_weights(l.variables.W)
            l = tf.nn.lrn(l, 2, bias=1.0, alpha=2e-5, beta=0.75, name='norm1')
            l = MaxPooling('pool1', l, 3, strides=2, padding='VALID')
            # 27
            l = Conv2D('conv2', l, filters=256, kernel_size=5, split=2)
            l = tf.nn.lrn(l, 2, bias=1.0, alpha=2e-5, beta=0.75, name='norm2')
            l = MaxPooling('pool2', l, 3, strides=2, padding='VALID')
            # 13
            l = Conv2D('conv3', l, filters=384, kernel_size=3)
            l = Conv2D('conv4', l, filters=384, kernel_size=3, split=2)
            l = Conv2D('conv5', l, filters=256, kernel_size=3, split=2)
            l = MaxPooling('pool3', l, 3, strides=2, padding='VALID')

            l = FullyConnected('fc6', l, 4096,
                               kernel_initializer=gauss_init,
                               bias_initializer=tf.ones_initializer())
            l = Dropout(l, rate=0.5)
            l = FullyConnected('fc7', l, 4096, kernel_initializer=gauss_init)
            l = Dropout(l, rate=0.5)
        logits = FullyConnected('fc8', l, 1000, kernel_initializer=gauss_init)
        return logits 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:33,代码来源:alexnet.py

示例11: backbone_scope

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def backbone_scope(freeze):
    """
    Args:
        freeze (bool): whether to freeze all the variables under the scope
    """
    def nonlin(x):
        x = get_norm()(x)
        return tf.nn.relu(x)

    with argscope([Conv2D, MaxPooling, BatchNorm], data_format='channels_first'), \
            argscope(Conv2D, use_bias=False, activation=nonlin,
                     kernel_initializer=tf.variance_scaling_initializer(
                         scale=2.0, mode='fan_out')), \
            ExitStack() as stack:
        if cfg.BACKBONE.NORM in ['FreezeBN', 'SyncBN']:
            if freeze or cfg.BACKBONE.NORM == 'FreezeBN':
                stack.enter_context(argscope(BatchNorm, training=False))
            else:
                stack.enter_context(argscope(
                    BatchNorm, sync_statistics='nccl' if cfg.TRAINER == 'replicated' else 'horovod'))

        if freeze:
            stack.enter_context(freeze_variables(stop_gradient=False, skip_collection=True))
        else:
            # the layers are not completely freezed, but we may want to only freeze the affine
            if cfg.BACKBONE.FREEZE_AFFINE:
                stack.enter_context(custom_getter_scope(freeze_affine_getter))
        yield 
开发者ID:tensorpack,项目名称:tensorpack,代码行数:30,代码来源:backbone.py

示例12: build_graph

# 需要导入模块: from tensorpack import tfutils [as 别名]
# 或者: from tensorpack.tfutils import argscope [as 别名]
def build_graph(self, seq, seq_len, label):
        batch_size = tf.shape(seq)[0]

        with argscope(
                    [
                        Conv2D, Deconv2D, GroupedConv2D, AvgPooling,
                        MaxPooling, BatchNorm, GlobalAvgPooling,
                        ResizeImages, SeparableConv2D
                    ],
                    data_format=self.data_format
                ), \
                argscope(
                    [Conv2D, Deconv2D, GroupedConv2D, SeparableConv2D],
                    activation=tf.identity,
                    use_bias=self.options.use_bias
                ), \
                argscope(
                    [BatchNorm],
                    center=False,
                    scale=False,
                    decay=self.options.batch_norm_decay,
                    epsilon=self.options.batch_norm_epsilon
                ), \
                argscope(
                    [candidate_gated_layer],
                    eps=self.options.candidate_gate_eps
                ):

            initializer = tf.random_uniform_initializer(-self.init_range, self.init_range)
            hid_to_fs_params = _init_feature_select(
                self.layer_info_list, 'master', self.options.feat_sel_lambda)
            seq, embedding_w = self._embed_input_if_int(seq, initializer=initializer)
            basic_cells = [
                self._basic_cell(
                    initializer=initializer,
                    hid_to_fs_params=hid_to_fs_params) for _ in range(self.num_lstms)
            ]
            cells = rnn.MultiRNNCell(basic_cells)
            state = cells.zero_state(batch_size, dtype=tf.float32)

            _, state = tf.nn.dynamic_rnn(
                cells, seq, initial_state=state, sequence_length=seq_len)

            cost = None
            cost, _variables = feature_to_prediction_and_loss(
                'rnn_pred', state, label, self.num_classes,
                self.options.prediction_feature, 1, is_last=True)
            self.cost = tf.identity(cost, name='cost')
            # TODO it is broken rn. because dynamic_rnn is not capatible with
            # hallu stats computation.
            self._build_hallu_stats_graph(self.cost)
            return self.cost 
开发者ID:microsoft,项目名称:petridishnn,代码行数:54,代码来源:recurrrent.py


注:本文中的tensorpack.tfutils.argscope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。