Pytorch (3) 썸네일형 리스트형 pytorch 여러 loss function의 결합 YOLO와 같이 logit에 대해 분할하여 여러 loss를 적용시키는 경우 pytorch에서 autograd가 정상 작동하는지 확인해보았다. 결론만 말하자면 logit을 인덱스 슬라이싱 할 경우 computational graph에서 인덱스 슬라이싱한 부분이 추적이 되어 logit의 일부만 떼어서 loss를 계산하더라도 적상적으로 역전파가 되는 것을 확인할 수 있다. logit = model(x) loss = criterion(logit[:5], y[:5]) 와 같은 코드라면 model이 logit[:5]까지 영향을 미치는 부분들만 autograd된다. [pytorch] gather와 scatter gather reference : https://pytorch.org/docs/stable/generated/torch.gather.html torch.gather — PyTorch 2.0 documentation Shortcuts pytorch.org scatter reference : https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_.html#torch.Tensor.scatter_ torch.Tensor.scatter_ — PyTorch 2.0 documentation Shortcuts pytorch.org gather는 input의 텐서에서 index에 따라 값들을 가져오는 텐서로 만드는 함수이다. scatter는 src의 텐서에서 값.. Pytorch 기초 공식 레퍼런스 : https://pytorch.org/docs/stable/index.html PyTorch documentation — PyTorch 2.0 documentation Shortcuts pytorch.org torch.tensor 파이토치의 가장 기본적인 클래스로 numpy의 ndarray와 같은 행렬을 다루는 클래스이다. tensor_a = torch.Tensor([1,2,3]) # 기본적인 생성 tensor_b = torch.Tensor(np.arange(10)) # ndarray로 생성도 가능하다 tensor_c = torch.arange(10) # 물론 torch에도 arange 함수가 있다. tensor_d = torch.IntTensor([1,2,3]) # int 타입의 텐서를.. 이전 1 다음