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


Python resnet_v2.resnet_arg_scope方法代码示例

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


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

示例1: Resnet

# 需要导入模块: from nets import resnet_v2 [as 别名]
# 或者: from nets.resnet_v2 import resnet_arg_scope [as 别名]
def Resnet(n_layers, imgs_in, weight_decay, batch_norm_momentum, is_training):
    assert n_layers in {50, 101, 152, 200}, 'unsupported n_layers'

    network = getattr(resnet_v2, 'resnet_v2_{}'.format(n_layers))
    with tf.contrib.slim.arg_scope(resnet_v2.resnet_arg_scope(weight_decay=weight_decay, batch_norm_decay=batch_norm_momentum)):
        features, _ = network(imgs_in, is_training=is_training, global_pool=False, output_stride=16)

    return features 
开发者ID:leimao,项目名称:DeepLab_v3,代码行数:10,代码来源:feature_extractor.py

示例2: endpoints

# 需要导入模块: from nets import resnet_v2 [as 别名]
# 或者: from nets.resnet_v2 import resnet_arg_scope [as 别名]
def endpoints(image, is_training):
    if image.get_shape().ndims != 4:
        raise ValueError('Input must be of size [batch, height, width, 3]')

    image = image - tf.constant(_RGB_MEAN, dtype=tf.float32, shape=(1,1,1,3))

    with tf.contrib.slim.arg_scope(resnet_arg_scope(batch_norm_decay=0.9, weight_decay=0.0)):
        _, endpoints = resnet_v2_50(image, num_classes=None, is_training=is_training, global_pool=True)

    endpoints['model_output'] = endpoints['global_pool'] = tf.reduce_mean(
        endpoints['resnet_v2_50/block4'], [1, 2], name='pool5', keep_dims=False)

    return endpoints, 'resnet_v2_50' 
开发者ID:knwng,项目名称:vehicle-triplet-reid,代码行数:15,代码来源:resnet_v2_50.py

示例3: graph

# 需要导入模块: from nets import resnet_v2 [as 别名]
# 或者: from nets.resnet_v2 import resnet_arg_scope [as 别名]
def graph(x, y, i, x_max, x_min, grad):
    eps = 2.0 * FLAGS.max_epsilon / 255.0
    num_iter = FLAGS.num_iter
    alpha = eps / num_iter
    momentum = FLAGS.momentum
    num_classes = 1001

    # should keep original x here for output

    with slim.arg_scope(inception_v3.inception_v3_arg_scope()):
        logits_v3, end_points_v3 = inception_v3.inception_v3(
            input_diversity(x), num_classes=num_classes, is_training=False)

    with slim.arg_scope(inception_v4.inception_v4_arg_scope()):
        logits_v4, end_points_v4 = inception_v4.inception_v4(
            input_diversity(x), num_classes=num_classes, is_training=False)

    with slim.arg_scope(inception_resnet_v2.inception_resnet_v2_arg_scope()):
        logits_res_v2, end_points_res_v2 = inception_resnet_v2.inception_resnet_v2(
            input_diversity(x), num_classes=num_classes, is_training=False, reuse=True)

    with slim.arg_scope(resnet_v2.resnet_arg_scope()):
        logits_resnet, end_points_resnet = resnet_v2.resnet_v2_152(
            input_diversity(x), num_classes=num_classes, is_training=False)

    logits = (logits_v3 + logits_v4 + logits_res_v2 + logits_resnet) / 4
    auxlogits = (end_points_v3['AuxLogits'] + end_points_v4['AuxLogits'] + end_points_res_v2['AuxLogits']) / 3
    cross_entropy = tf.losses.softmax_cross_entropy(y,
                                                    logits,
                                                    label_smoothing=0.0,
                                                    weights=1.0)
    cross_entropy += tf.losses.softmax_cross_entropy(y,
                                                     auxlogits,
                                                     label_smoothing=0.0,
                                                     weights=0.4)
    noise = tf.gradients(cross_entropy, x)[0]
    noise = tf.nn.depthwise_conv2d(noise, stack_kernel, strides=[1, 1, 1, 1], padding='SAME')
    noise = noise / tf.reduce_mean(tf.abs(noise), [1, 2, 3], keep_dims=True)
    noise = momentum * grad + noise
    x = x + alpha * tf.sign(noise)
    x = tf.clip_by_value(x, x_min, x_max)
    i = tf.add(i, 1)
    return x, y, i, x_max, x_min, noise 
开发者ID:dongyp13,项目名称:Translation-Invariant-Attacks,代码行数:45,代码来源:attack_iter.py


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