분류 전체보기(115)
-
[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 -
L1, L2 Norm/Regularization
Norm [선형대수학] 벡터의 크기(magnitude) 또는 길이(length)를 측정하는 방법 (주의) 차원 != 길이 L1, L2 Norm 이 식에서 p=1이면 L1 Norm, p=2이면 L2 Norm s.sum(dim=1, keepdim=True) # L1 s.pow(2).sum(dim=1, keepdim=True).sqrt() # L2 L1 Norm L1 Norm 은 벡터 p, q 의 각 원소들의 차이의 절대값의 합 L2 Norm L2 Norm 은 벡터 p, q 의 유클리디안 거리(직선 거리) 위 식은 p = (x_1, x_2, ... , x_n), q = (0, 0, ... , 0) 일 때라고 할 수 있음. 검정색 두 점사이의 L1 Norm : 빨간색, 파란색, 노란색 L2 Norm: 초록색 L..
2021.05.22 -
__getitem__
리스트처럼 클래스의 인스턴스 자체도 슬라이싱을 할 수 있도록 만들 때 필요한 속성이 __getitem__이라는 속성 1. 직접 인스턴스에 접근해 슬라이싱 class CustomNumbers: def __init__(self): self._numbers = [n for n in range(1, 11)] a = CustomNumbers() a._numbers[2:5] # [3, 4, 5] 2. getitem 특별 메소드로 인스턴스 변수에 접근하지 않고 객체 자체를 통해 슬라이싱을 구현 __getitem__함수는 인덱스를 인수로 받아야 한다. class CustomNumbers: def __init__(self): self._numbers = [n for n in range(1, 11)] def __getit..
2021.05.21 -
[PyTorch] tensor 부등호 연산 (?), list와 차이점
tensor로 만들어줄 경우 import torch data = [[1, 2],[3, 4]] x_data = torch.tensor(data) pos = x_data > 0 print(pos) 결과 List일 경우 data = [[1, 2],[3, 4]] pos = data > 0 print(pos) 이 연산 자체가 불가능 for문 사용해야함 data = [[1, 2],[3, 4]] pos = [[a > 0, b > 0] for a, b in data] print(pos)
2021.05.13 -
DeOldify
Overview ※ fasi.ai의 기술 Decrappification(GAN사용안함) - > DeOldify (GAN + UNet) Proposed Solution Dynamic Unet 기반 ( 공식적 UNet은 아니고 fast.ai에서 구현한..? 것으로 보임) : 기존 U-Net + Self Attention + Spectral Normalization (정확한 건 아니고 추측....) SAGAN Resnet backbone (Pretrained)Unet NoGAN(학습방법) augmentation : 극단적인 밝기/대비 증가로 old/low quality image나 film대한 robustness 높임, 무의미한 노이즈 대한 민감도 줄이기 위한 gaussian noise 추가 transfer ..
2021.05.10 -
Python argparse
import argparse argparse는 python에 기본으로 내장되어 있다. 더보기 The argparse module makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages and issues errors when users give the program invalid arguments. import argpar..
2021.05.09