본문 바로가기

전체 글117

[Object Detection] DETR(DEection TRasformer ECCV2020)리뷰 및 구현 안녕하세요 Pulluper 입니다 :) 이번시간에는 Transformer 를 이용한 Object Detection 방법인 DETR 에 대하여 알아보겠습니다! https://arxiv.org/abs/2005.12872 본 포스팅의 내용은 크게 Introduction, Network, Loss 로 이루어집니다. 😎 1. Introduction DETR은 Object Detection 방법을 set prediction 문제로 보았습니다. 이를 통한 효과는 hand-designed component 를 없앨 수 있다는 것입니다. 예를들어 nms와 anchor 생성등이 있습니다. 이 논문의 contribution은 크게 2가지가 있다고 생각합니다. Network(Transformer architecture) Lo.. 2023. 2. 6.
[DNN] multi-head cross attention vs multi-head self attention 비교 안녕하세요 pulluper 입니다. attention 을 사용한 모듈을 보면, 하나의 인풋이 들어와서 q, k, v 가 같은 length를 가지는 경우가 있고, q의 길이와 k, v의 길이는 다른 경우를 왕왕 볼 수 있습니다. 예를들어 DETR의 decoder의 경우에서 사용하는 attention 중 하나는 q, k, v 의 길이가 모두 같지 않습니다. 이때 timm의 구현과 비슷하게 다음을 구현해 보겠습니다. 모두 같은 길이를 같는 모듈은 Multi-head Self Attention(MSA) 이라 하겠고, 그렇지 않으면 Multi-head Cross Attention(MCA) 이라 하겠습니다. 다음은 그것들의 구현입니다. import torch import torch.nn as nn import to.. 2023. 2. 2.
[Pytorch] network parameter 갯수 확인 1. print(sum(p.numel() for p in model.parameters() if p.requires_grad)) 예를들어 다양한 모델에 대하여 from torchvision.models import * if __name__ == '__main__': model = vgg11() print("vgg11 : ", sum(p.numel() for p in model.parameters() if p.requires_grad)) model = vgg13() print("vgg13 : ", sum(p.numel() for p in model.parameters() if p.requires_grad)) model = vgg16() print("vgg16 : ", sum(p.numel() for p i.. 2023. 2. 1.
UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor'). 텐서사이의 나눗셈을 할 때, 다음과 같은.. 2023. 1. 30.
[Pytorch] torch.flatten() 사용하기 torch.flatten(t, s) 함수는 s 차원 이후에 평평하게 펴라는 뜻이다. torch.flatten(t, s, e) 이렇게 사용하면 t 차원부터 e차원까지만 평평하게 펴라는 뜻 아래는 예제 t = torch.tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) # t.size() is [2, 2, 2] torch.flatten(t, 0) tensor([1, 2, 3, 4, 5, 6, 7, 8]) torch.flatten(t, 1) tensor([[1, 2, 3, 4], [5, 6, 7, 8]]) torch.flatten(t, 2) tensor([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) torch.equal(t, torch.flatten(t, 2.. 2023. 1. 26.
[Theme 07] Back Propagation 설명 안녕하세요 pulluper 입니다. 😄 이번 포스팅은 드디어 Back Propagation에 대하여 다뤄보도록 하겠습니다. 지난 시간에 다룬 MLP에 대하여 이어서 다뤄보겠습니다. 다음과 같은 MLP 가 있다고 하겠습니다. 이를 그림으로 표시하면 다음과 같습니다. 2개의 feature 를 갖는 하나의 input을 네트워크에 넣었을때의 그림입니다. x1, x2 에서 h1, h2, h3 로 갈때를 수식으로 표현하면 다음과 같습니다. (h1, h2, h3) = $\phi$ (XW + B) 로 표현할 수 있습니다. $\phi$ 는 activation function 입니다. 혹은 다음과 같이 XW + B 를 matrix multiplication으로 한번에 표현 할 수 있습니다. 이런 방식으로 전체 네트워크 o.. 2023. 1. 25.