04-17 04:21
Notice
Recent Posts
Recent Comments
관리 메뉴

BAN2ARU

[Python/ Pytorch] torch.nn.BatchNorm2d() 본문

Language/Python

[Python/ Pytorch] torch.nn.BatchNorm2d()

밴나루 2022. 4. 21. 16:11
반응형

https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm2d.html를 기반으로 작성하였음.

CLASS
torch.nn.BatchNorm2d(
	num_features, eps=1e-05, momentum=0.1, affine=True, 
	track_runing_stats=True, device=None, dtype=None
)

Batch Normalization

y=xE[x]Var[x]+ϵγ+β

각 batch 별로 평균(mean)과 분산(variance)를 이용해 정규화하는 것을 의미함


파라미터

  • num_features : input size (N,C,H,W)에서 C (N은 batch-size, C는 channel 수, H,W는 height,width를 의미함)
  • eps : Numerical stability를 위해 분모에 추가된 값으로서 default는 0.1임 (위의 식에서 ϵ에 해당되며 분모가 0이 되어 NaN이 되는것을 방지하기 위함)
  • momentum : running_mean과 running_var의 계산을 위해 사용되는 값으로서 default는 0.1임. (Trainining을 수행시에는 batch단위의 평균과 분산으로 batch-norm을 수행하고, Test를 수행시에는 축적된 running_mean/variance를 사용 - [1] 참조 - Bessel’s correlation 관련은 [3] 참조)
  • affine : Boolean value이며, True로 설정시에, 이 모듈에 학습가능한 affine parameter가 있음. Default는 True임. (False로 설정시에 위의식에서 γ=1, β=0 임)
  • track_running_stats : Boolean value이며, True로 설정시에 이 모듈은 running mean과 variance를 track하고 False로 설정시에는 이 모듈이 track하지 않고, running_mean과 running_var를 None으로 초기화하며, 이 값이 None인 경우에는 이 모듈은 항상 batch statistics를 사용함. Default는 True임. ([2] 참조)

Shape

  • Input : (N,C,H,W)
  • Output : (N,C,H,W)

Reference

[0] https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm2d.html

[1] https://eehoeskrap.tistory.com/430

[2] https://discuss.pytorch.org/t/pytorch-documentation-for-batchnorm/50804/10

[3] https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=af472&logNo=190291513

728x90
Comments