ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 8일
    부스트캠프 Ai tech/2주차 2022. 1. 26. 14:37

    torch.nn.Module

    • 딥러닝을 구성하는 Layer의 base Class
    • Input, Output, Forward, Backward정의
    • 학습의 대상이 되는 parameter(tensor) 정의 
    class MyLiner(nn.Module):
        def __init__(self, in_features, out_features, bias=True):
            super().__init__()
            self.in_features = in_features
            self.out_features = out_features
            
            self.weights = nn.Parameter(
                    torch.randn(in_features, out_features)) # output과 크기를 맞춰주기 위함
            
            self.bias = nn.Parameter(torch.randn(out_features)) # bias 크기는 output과 같아야함
    
        def forward(self, x : Tensor):
            return x @ self.weights + self.bias

     

    Backward

    for epoch in range(epochs):
    	optimizer.zero_grad() # <- 이전의 grad값이 다음 단계에 영향을 안미치도록 초기화(필수)
        
        outputs = model(inputs) # <- y^(y hat)
        
        loss = criterion(outputs, labels) # criterion = torch.nn.MSELoss(size_average=False)
        
        loss.backward()
        
        optimizer.step()

     

    DataLoader 클래스

    • Data의 Batch를 생성해주는 클래스
    • 학습직전(GPU feed전) 데이터의 변환을 책임
    • Tensor로 변환 + Batch 처리가 메인 업무
    • 병렬적인 데이터 전처리 코드의 고민 필요

    '부스트캠프 Ai tech > 2주차' 카테고리의 다른 글

    로지스틱 회귀  (0) 2022.01.30
    10일  (2) 2022.01.28
    9일  (0) 2022.01.27
    7일 - 과제 정리  (5) 2022.01.26
    6일 - torch.gather  (0) 2022.01.24

    댓글

Designed by Tistory.