Loading...
2023. 5. 8. 03:43

pytorch - flatten과 averaging pooling, training 방법 기본기, layer 구성법

1. flatten vs. average pooling flatten은 feature map을 벡터로 적절한 순서대로 쌓고 import torch t = torch.tensor([[[1,2], [3,4]], [[5, 6], [7,8]]]) print(torch.flatten(t)) tensor([1, 2, 3, 4, 5, 6, 7, 8]) print(torch.flatten(t, start_dim = 1)) tensor([[1, 2, 3, 4], [5, 6, 7, 8]]) feature map이 [1,2,3,4]랑 [5,6,7,8]인데 이 둘을 2가지 방식으로 flatten시켰다? 이건 그림 안그려봐도 결과 코드가 이해가 될듯.. [1,2,3,4]랑 [5,6,7,8]을 적절하게 쌓았네 ----------..

2023. 4. 26. 00:10

pytorch에서 loss 기본개념 재활

1. loss input data로부터 forward를 통해 계산한 예측된 결과 output input의 정답 label인 target과의 차이가 loss이다. loss는 error, cost로 불리기도 한다. backward 과정에 의해 loss가 update된다. output과 target의 차이를 어떻게 정의할 것인가? 문제와 task 목적에 따라 제곱오차, cross entropy 등 여러가지로 정의할 수 있다. loss에 따라 차이는 바뀔 것이고 class마다도 다를 수 있는데 loss의 선택에 따라 training중 parameter 업데이트 과정도 달라지므로 신중하게 선택해야한다. 2. nn.Module loss class도 nn.Module을 상속받는다… 따라서 __init__와 forwa..

2023. 4. 24. 03:23

pytorch를 이용한 training process 기본기 완벽하게 이해하기

1. training을 위해 필요한 것? training을 위해 dataset, dataloader를 준비해서 data를 효율적으로 뽑아낼 준비를 했고 설계한 model과 loss, optimizer, learning rate, scheduler, metric 등을 준비했다면 학습 준비 완료! 2. model.train() train하기 전에 model을 trainable하게 변경시키는 함수? 그런데 분명 model 설계할 때 나는 각종 parameter의 requires_grad=True로 한것같은데 굳이 해야하나??? batchnorm이나 dropout같은 것이 training 과정이랑 evaluation 과정에서 다르게 작동해야한다고 알려져있어서 train mode와 eval mode를 구분하기 위..