'AI 구현' 카테고리의 글 목록
본문 바로가기

AI 구현10

[Pytorch] view, reshape, permute 함수 : 차원 재구성 텐서의 크기를 바꾸는 view, reshape 함수와 차원 순서를 바꾸는  reshape 함수에 대해 알아봅시다. view 함수view는 텐서의 크기를 바꾸는 함수로, 기존의 데이터와 같은 메모리 공간을 공유하고 contigious 할 때 사용 가능합니다. (아닌 경우 에러 발생)  import torchx = torch.randn(4,4)y = x.view(2,2,4)z = x.view(-1,8)print(x.size())print(y.size())print(z.size())"""[출력]torch.Size([4, 4])torch.Size([2, 2, 4])torch.Size([2, 8])""" reshape 함수reshape는 view 처럼 텐서의 크기를 바꿔주는 함수입니다. 약간의 다른점이 있다면, .. 2024. 9. 8.
[Pytorch] gather 함수 : index에 따라 값을 수집/추출 주어진 index 텐서에 따라 input 텐서의 값을 추출하여 새로운 텐서를 생성하는 gather 함수에 대해 알아봅시다. gather 함수torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor[Parameters]* input: 입력 텐서* dim: gather 사용 시, 기준이 되는 축 (0이면 행 방향, 1이면 열 방향)* index: 특정 값을 값들을 수집할 위치를 지정하는 index 텐서(input tensor와 index tensor의 dimension이 동일해야함)  1) dim=0 (행 방향)인 경우 t = torch.tensor([[1, 2], [3, 4]])index = torch.tensor([[0, 0], [.. 2024. 9. 3.
[Pytorch] scatter_ 함수 : index에 따라 특정 위치 값을 직접 삽입/수정 주어진 index에 따라 원본 텐서의 특정 위치에 값을 직접 수정하는 scatter_ 함수에 대해 알아봅시다. torch.scatter 함수와 torch.scatter_ 함수 다른점torch.scatter 함수 : 원본 텐서를 수정하지 않고, 새로운 텐서를 반환 (out-of-place)torch.scatter_ 함수 : 원본 텐서를 직접 수정함 (in-place) torch.scatter_ 함수Tensor.scatter_(dim, index, src, *, reduce=None) → Tensor[Parameters]* dim: scatter 사용 시, 기준이 되는 축 (0이면 행 방향, 1이면 열 방향)* index: element들의 index, 숫자를 어떤식으로 옮길지 결정하는 규칙* src: 옮길.. 2024. 9. 3.
[Pytorch] broadcast_tensors 함수 : 텐서 확장 및 연산 브로드캐스팅 기능을 이용해 두 텐서를 같은 크기로 확장하는 broadcast_tensors 함수에 대해 알아봅시다. broadcast_tensors 함수브로드캐스팅은 서로 다른 크기의 텐서를 같은 크기로 확장하여 연산을 가능하게 합니다. 이 함수를 쓰려면, 아래 조건을 만족해야 합니다. [브로드캐스팅 규칙]비교하는 두 차원 크기가 같거나 두 차원 중 하나의 크기가 1이어야 함 * 브로드캐스팅 O x = torch.rand(3,6)y = torch.rand(1,6)a,b = torch.broadcast_tensors(x,y)print(a.size())print(b.size())"""[출력]torch.Size([3, 6])torch.Size([3, 6])"""  * 브로드캐스팅 X x = torch.rand.. 2024. 9. 3.
[Pytorch] squeeze,unsqueeze 함수 : 차원 삭제, 차원 삽입 크기가 1인 차원을 삭제하는 squeeze 함수와 삽입하는 unsqueeze 함수에 대해 알아봅시다. squeeze 함수torch.squeeze(input, dim=None) → Tensor[Parameters]* input (Tensor): 입력 텐서* dim (int or tuple of ints, optional): 값이 지정돼 있다면 특정 차원에서 squeeze됨 차원이 1인 차원을 제거해줍니다. 특정 차원을 지정하면, 해당 차원의 크기가 1인 경우만 제거하고 1이 아니라면 그대로 유지합니다. import torchx = torch.rand(1,2,3,4,1)print(x.squeeze().size())print(x.squeeze(0).size())print(x.squeeze((0,1,2,3))... 2024. 9. 3.
Evaluation Metric (MDR, FAR, MAE) 정리 딥러닝 모델의 성능을 볼때 자주 쓰이는 confusion matrix와 그와 관련된 여러 평가지표에 대해 알아봅시다. 그리고 논문 [1] 에서 등장하는 평가지표 Miss detection rate (MDR), False alarm rate (FAR), Mean absolute error (MAE)의 의미를 이해해봅시다. Confusion Matrix 컴퓨터가 이진 분류 문제를 푼다고 했을 때, 두 개의 클래스를 얼마나 헷갈려하는지 나타낸 걸 confusion matrix라고 합니다. confusion matrix는 분류 모델의 정확도를 평가하기 위해 사용됩니다. TP (True Positive) : 실제로 positive인 값을 positive라고 잘 예측함 FP (False Positive) : 실제로.. 2024. 8. 27.