728x90
반응형
Resnet18을 활용한 코드를 공부하다가 나온 self.model.fc.in_features 의 의미를 찾아봤습니다.
class Network(nn.Module):
def __init__(self,num_classes=136):
super().__init__()
self.model_name='resnet18'
self.model=models.resnet18()
self.model.conv1=nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3, bias=False)
self.model.fc=nn.Linear(self.model.fc.in_features, num_classes)
def forward(self, x):
x=self.model(x)
return x
여기서 model.fc.in_features는
model의 fully connected layer(Linear layer)의 input의 수를 의미합니다
nn.Linear의 생성자 메소드를 보면 in_features를 찾을 수 있습니다.
def __init__(self, in_features, out_features, bias=True):
super(Linear, self).__init__()
self.in_features = in_features # num inputs
self.out_features = out_features # num outputs
self.weight = Parameter(torch.Tensor(out_features, in_features))
if bias:
self.bias = Parameter(torch.Tensor(out_features))
참고자료:
https://discuss.pytorch.org/t/what-does-the-fc-in-feature-mean/4889
728x90
반응형
'Data Science > Deep Learning' 카테고리의 다른 글
캐글 GPU 아끼는 방법! (코드 첨부) (0) | 2023.01.25 |
---|---|
Face Detection 의 역사 및 응용코드 (0) | 2023.01.25 |
OpenAI DALLE2 사용 후기 (Midjourney와 비교) (0) | 2023.01.14 |
경사하강법 Python 파이썬 코드로 구현하기 (0) | 2023.01.13 |
1*1 합성곱층 (Convolution layer) 원리 및 목적 설명 (1) | 2022.12.22 |
댓글