alexnet_model.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:tensorflow_face 作者: ZhihengCV 项目源码 文件源码
def inference(images, num_classes, is_training=True, scope='alexnet_v2'):
    """Build Inception v3 model architecture.

     See here for reference: http://arxiv.org/abs/1512.00567

    Args:
        images: Images returned from inputs() or distorted_inputs().
        num_classes: number of classes
        for_training: If set to `True`, build the inference model for training.
        Kernels that operate differently for inference during training
        e.g. dropout, are appropriately configured.
        restore_logits: whether or not the logits layers should be restored.
        Useful for fine-tuning a model with different num_classes.
        scope: optional prefix string identifying the ImageNet tower.

    Returns:
        Logits. 2-D float Tensor.
        Auxiliary Logits. 2-D float Tensor of side-head. Used for training only.
    """
    # Parameters for BatchNorm.
    batch_norm_params = {
        # Decay for the moving averages.
        'decay': BATCHNORM_MOVING_AVERAGE_DECAY,
        # epsilon to prevent 0s in variance.
        'epsilon': 0.001,
        # calculate moving average or using exist one
        'is_training': is_training
    }
    # Set weight_decay for weights in Conv and FC layers.
    with arg_scope([layers.conv2d, layers.fully_connected],
                   activation_fn=nn_ops.relu,
                   biases_initializer=init_ops.constant_initializer(0.1),
                   weights_regularizer=regularizers.l2_regularizer(FLAGS.weight_decay)):
        with arg_scope([layers.conv2d],
                       normalizer_fn=layers.batch_norm,
                       normalizer_params=batch_norm_params):
            logits, endpoints = alexnet_v2(
                images,
                num_classes=num_classes,
                dropout_keep_prob=0.8,
                is_training=is_training,
                scope=scope
            )

    # Add summaries for viewing model statistics on TensorBoard.
    _activation_summaries(endpoints)

    return logits
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号