개념공부/기타
PyTorch nn.Linear
Zach Choi
2023. 2. 6. 22:05
728x90
반응형
참조 : https://pytorch.org/docs/stable/generated/torch.nn.Linear.html
Fully Connected Layer 구성 시 기본적으로 선택하는 식 중 하나
입력 데이터 x에 대해 Linear Transformation (선형 변환)을 계산한다.
$$ y = xA^{T}+b $$
class Torch.nn.Linear (in_features, out_features, bias=True, device=None, dtype=None)
Parameters:
- in_features (int) : input sample의 size
- out_features (int) : output sample의 size
- bias (bool) : (b term), Default : True. False로 설정하면 b term에 대한 학습은 이루어지지 않는다.
Shape:
- Input : (*, H_in) - * means any number of dimensions, H_in = in_features
- Output : (*, H_out) - H_out = out_features
Variables: (학습되는 변수들)
- weight : Linear Transformation의 A에 해당한다. Shape - (out_feature, in_feature). 가중치들은 입력 Feature의 개수를 역수 취한 값의 제곱근 값의 범위로 초기화 된다고 한다. (PyTorch 공식 문서) 왜지..?
- bias : Linear Transformation의 b에 해당한다. Shape (out_features). 이 값도 weight와 동일한 범위로 초기화 된다.
728x90
반응형