pytorch(9)
-
docker로 ubuntu18.04 /cuda10.1 /cudnn7 /opencv4.4.0/pytorch1.4.0 환경 만들기
프로젝트 진행 중 ubuntu 18.04, cuda 10.1, cudnn 7, opencv 4.4.0, pytorch 1.4.0 의 환경을 구성해야 하는 일이 생겼다. docker로 가상환경을 구상하고자 한 것은 반복되는 서버 초기화에 지쳤고...^^ conda환경은 이제 트렌디하지 않기 때문이다 시간이 많이 없고 처음 해보는 거라 깊은 이해없이 하게 된 감이 없지않아 있지만 ㅠㅠ docker에 대한 깊은 이해는 앞으로 해가도록 하고 일단 이 환경을 구성하는데 성공한 것에 박수를 치면서 ㅎㅎㅎㅎ 경험을 공유하고자 한다 ubuntu 18.04환경의 원격서버에서 진행하였다 1. base가 되어줄 nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04 이미지 pull https://gith..
2021.08.11 -
[pytorch] nn.Upsample
주어진 멀티채널 1D / 2D / 3D 데이터를 업샘플링한다. 인풋데이터는 minibatch x channels x [optional depth] x [optional height] x width 형태로 가정되나, spatial input(2D)은 4D 텐서, volumetric input(3D)은 5D텐서가능한 알고리즘 : nearest neighbor, linear, bilinear, bicubic, 3D이상의 데이터에 대해서는 trilinear parameters size (int/tuple) : output 사이즈 scale_factor(float/tuple) : Depth, Height, Width에 입력받은 정수 만큼 곱해준다. (1,1,2,2) 가 인풋으로 들어오면 (1,1,4,4)가 된다...
2021.06.16 -
[Pytorch] nn.ReflectionPad2d
input tensor를 input boundary의 reflection(반사)를 이용해서 패딩 적용 2차원 아닌 N차원 패딩을 이용하려면 torch.nn.functional.pad()를 사용 padding은 int형이나 tuple형 : 패딩 사이즈. int형이면 모든 바운더리에 같은 패딩을 적용. 4-tuple이면 (padding_left, padding_right, padding_top, padding_bottom)으로 적용 Input: (N, C, H_in, W_in) Output: (N, C, H_out, W_out) W_out = W_in + padding_left + padding_right H_out = H_in + padding_top + padding_bottom https://pyt..
2021.06.16 -
[Pytorch] Initializer (torch.nn.init)
torch.nn.init의 간단한 initializer들을 살펴보겠다 xavier같은 초기화기법들은 따로 다루기 1. torch.nn.init.normal_(tensor, mean=0.0, std=1.0) input tensor을 N(mean, std^2)의 normal distribution(정규분포)에 따라 초기화 2. torch.nn.init.uniform_(tensor, a=0.0, b=1.0) input tensor을 U(a, b)의 uniform distribution에 따라 초기화 * uniform distribution ? [a, b]의 범위에서 모든 값의 확률이 동일한 분포 3. torch.nn.init.constant_(tensor, val) input tensor를 특정 값 val로 ..
2021.06.15 -
[Pytorch] torch.sort
torch.sort(input, dim=-1, descending=False, stable=False, *, out=None) -> (Tensor, LongTensor) input (Tensor) – the input tensor. dim (int, optional) – sort할 차원 descending (bool, optional) – 내림차순/올림차순 여부 stable (bool, optional) – sorting routine을 안정적으로 만들어 equivalent의 순서가 유지되도록 보장합니다. stable=True only works on the CPU for now. 일반 Python list의 sort와 달리 바뀐 인덱스를 담고 있는 텐서를 반환해주기 때문에, 아주 유용하게 쓸 수 있다
2021.05.22 -
[Pytorch] torch.no_grad
기록을 추적하는 것(과 메모리를 사용하는 것)을 방지하기 위해, 코드 블럭을 with torch.no_grad(): 로 감쌀 수 있음. https://pytorch.org/docs/stable/generated/torch.no_grad.html no_grad — PyTorch 1.8.1 documentation Shortcuts pytorch.org gradient 계산이 되지 않게 하는 Context-manager gradient calculation을 금지하는 것은 inference에서 유용 (Tensor.backward()를 호출하지 않는다는 가정하에) 이 context 내부에서 새로 생성된 tensor들은 requires_grad = False상태가 됨 메모리 사용량을 아껴줌 thread loca..
2021.05.22