batchnorm2d参数 torch_Pytorch-nn.BatchNorm2d()

本文详细介绍了PyTorch中的BatchNorm2d模块,并提供了使用示例,通过代码解释了批量归一化的过程,包括权重、偏置、平均值和方差的计算。此外,还提到了BatchNorm在网络中的作用和测试时的注意事项。
摘要由CSDN通过智能技术生成

Pytorch官方文档:

测试代码:

转自:https://blog.csdn.net/tmk_01/article/details/80679549

import torch

import torch.nn as nn

m = nn.BatchNorm2d(2,affine=True) #weight(gamma)和bias(beta)将被使用

input = torch.randn(1,2,3,4)

output = m(input)

print(“输入图片:”)

print(input)

print(“归一化权重(公式中的gamma):”)

print(m.weight)

print(“归一化偏置(公式中的beta):”)

print(m.bias)

print(“归一化的输出:”)

print(output)

print(“输出的尺度:”)

print(output.size())

# i = torch.randn(1,1,2)

print(“输入的第一个维度:”)

print(input[0][0])

firstDimenMean = torch.Tensor.mean(input[0][0])

firstDimenVar= torch.Tensor.var(input[0][0],False) #Bessel’s Correction贝塞尔校正不会被使用

print(m.eps)

print

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值