码迷,mamicode.com
首页 > 其他好文 > 详细

PyTorch中的nn.BatchNorm2d

时间:2020-04-17 00:08:03      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:details   详细   features   elf   ack   and   mod   log   const   

class _NormBase(Module):   #源码
    """Common base of _InstanceNorm and _BatchNorm"""
    _version = 2
    __constants__ = [‘track_running_stats‘, ‘momentum‘, ‘eps‘,
                     ‘num_features‘, ‘affine‘]

    def __init__(self, num_features, eps=1e-5, momentum=0.1, affine=True,
                 track_running_stats=True):
        super(_NormBase, self).__init__()
        self.num_features = num_features
        self.eps = eps
        self.momentum = momentum
        self.affine = affine
        self.track_running_stats = track_running_stats
        if self.affine:
            self.weight = Parameter(torch.Tensor(num_features))
            self.bias = Parameter(torch.Tensor(num_features))
        else:
            self.register_parameter(‘weight‘, None)
            self.register_parameter(‘bias‘, None)
        if self.track_running_stats:
            self.register_buffer(‘running_mean‘, torch.zeros(num_features))
            self.register_buffer(‘running_var‘, torch.ones(num_features))
            self.register_buffer(‘num_batches_tracked‘, torch.tensor(0, dtype=torch.long))
        else:
            self.register_parameter(‘running_mean‘, None)
            self.register_parameter(‘running_var‘, None)
            self.register_parameter(‘num_batches_tracked‘, None)
        self.reset_parameters()

torch.nn.BatchNorm1d(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)

详细见https://blog.csdn.net/LoseInVain/article/details/86476010

PyTorch中的nn.BatchNorm2d

标签:details   详细   features   elf   ack   and   mod   log   const   

原文地址:https://www.cnblogs.com/dyclown/p/12716841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!