Loading...
2024. 6. 7. 23:58

linear transformation에 대해 간단하게

matrix나 tensor는 linear transformation이다.    1차원의 [0,1]의 선분을 linear transformation T(x)=3x를 통해 변환하면 3배 늘어난 선분 [0,3]이 된다    주어진 2차원의 정사각형 ABCD를 linear transformation     을 통해 변환하면 2배 늘어나고 회전된 정사각형 A’B’C’D’이 된다    조금 더 복잡하게 주어진 정사각형을 늘리거나 회전시키거나 비틀어버리거나 하더라도 linear transformation 수학적으로 vector space V,W에 대하여 f: V → W가 linear map이라는 것은  임의의 vector u,v ∈ V와 scalar c가  $f(u+v)=f(u)+f(v)$ , $f(cu)=cf(u)..

2024. 4. 14. 02:14

torch.where()로 tensor내 특정 원소의 위치를 찾기

gaussian heatmap에서 landmark localization (x,y) 좌표를 얻어내는 방법은 landmark localization이라는 것이 가장 주목할 부분, heatmap에서 가장 밝게 빛나는 부분이므로 heatmap의 activation value중 가장 큰 값의 (x,y)좌표를 얻어오면 된다 주어진 heatmap tensor hm에서 최댓값 부분을 어떻게 찾아오느냐? hm에서 최댓값을 가져오려면 hm.max()나 torch.max(hm)을 사용한다 hm==torch.max(hm)을 하면 True, False를 원소로 가지는 hm 크기와 동일한 tensor가 나온다 True의 위치를 찾는게 목적이라고 할 수 있다. 어떻게 찾을까? torch.where()나 np.where()함수는 ..

2024. 4. 13. 00:33

Pytorch의 computational graph와 backward()에 대해 이해하기

1. computational graph   computational graph라는 것은 pytorch가 최종 변수에 대한 (위 그림에서는 L)  forward pass를 통해 계산되는 모든 과정이 graph 형태로 저장되어 있는 것을 의미한다. 위의 그림은 a, b, c, d, L, w1,w2,w3,w4 9개의 변수 값들의 계산 과정이 기록되어 있는 computational graph이다. 위 그림에서 예를 들어 c를 계산할려면 a와 w2의 어떤 연산으로 c가 계산되어진다는 의미다. 이렇게 저장을 해놓으면 chain rule에 의한 backward pass 계산이 쉬워진다.  2. backward forward pass를 통해 변수에 대해 계산을 하면 pytorch에서 알아서 computational ..

2024. 4. 11. 03:27

Pytorch에서 두 tensor가 서로 같은지 비교하고 싶다면?

a = torch.tensor([1,2,3,4]) b = torch.tensor([2,3,5,1]) 위와 같은 두 텐서가 있을때, 서로 같은지 알고싶다.. 크기가 작으니 바로 보면 다르다는 것 알 수 있는데 얘 둘을 비교해보라고 한다면? a == b 해버리면... 예상하는 결과와 다르게 나온다 이렇게 하면 진짜 True인지 False인지 바로 알기 어렵다.. tensor의 원소 하나하나 True인지 False인지 체크해야하거든.. torch.all()을 이용해서 boolean tensor의 모든 boolean을 비교해서... 전부 True이면 True이고 하나라도 False이면 False https://doheejin.github.io/pytorch/2021/02/13/pytorch-function.ht..

2023. 11. 7. 12:21

pytorch의 tensor를 plt.imshow()했더니 TypeError: Invalid shape for image data

https://velog.io/@olxtar/Torchvision-PIL-torch.Tensor-PIL-Image [Torchvision / PIL] torch.Tensor PIL Image PIL/Numpy Array/Torch Tensor 이미지끼리 변환하기 / torchvision.transforms.ToTensor() / torchvision.transforms.ToPILImage velog.io PIL이나 opencv로 이미지를 열때는 (height, width, channel) 순으로 shape를 가지게 된다 img = Image.open('/content/karina.jpeg') img2 = cv2.imread('/content/karina.jpeg') print(np.array(img).s..

2023. 5. 1. 03:25

pytorch - 모델의 parameter 제대로 이해하기 재활치료

1. model이 가지는 parameter 확인하기 model에 정의된 modules가, 가지고 있는 forward 계산에 쓰일 parameter tensor가 저장되어 있음 .state_dict(), .parameters() 함수를 이용하여 저장된 parameter를 볼 수 있음 .state_dict()는 무엇이 무엇의 parameter인지 확인 가능 .parameters()는 그냥 parameter를 출력해서 뭐가 뭔지 확인은 어렵다 parameter는 weight와 bias로 이루어져있다는 것을 알 수 있다 2. parameter tensor parameter는 tensor 기반의 class 그냥 tensor가 있고, grad를 가질 수 있는 parameter tensor라는 것이 있는거임.. 이거..