其他分享
首页 > 其他分享> > BatchN

BatchN

作者:互联网

from torch import nn
import torch

torch.manual_seed(21)
input = torch.randn(1,3,3,3).cuda()
input[0][0] = 0
m3 = nn.BatchNorm2d(3, eps=0, momentum=0.5, affine=True, track_running_stats=True).cuda()
m3.running_mean = (torch.ones([3])*4).cuda()     # 设置模型的均值是4
m3.running_var = (torch.ones([3])*2).cuda()      # 设置模型的方差是2


BN_input = m3(input)
BN_output = BN_input[0][0]


obser_mean = torch.Tensor([input[0][i].mean() for i in range(3)]).cuda()
# 输入数据的方差
obser_var = torch.Tensor([input[0][i].var() for i in range(3)]).cuda()
# 编码归一化

output3_source = (input[0][0] - obser_mean[0])/(pow(obser_var[0] + m3.eps,0.5))
my_output = output3_source

在这里插入图片描述

标签:obser,torch,BatchN,cuda,m3,var,input
来源: https://blog.csdn.net/highoooo/article/details/122824868