분류 전체보기(115)
-
[Pytorch] torch.utils.data의 Dataset과 DataLoader
torch.utils.data.Dataset 이 클래스를 상속받아 Dataset instance를 생성해주는 class 구현 torch의 dataset은 두가지의 형식이 있음 Map-style dataset - index가 존재해 data[index]로 데이터 참조가 가능하다. - __getitem__과 __len__의 오버라이팅이 필요하다. - ‘__len__’ 에서는 학습 데이터의 갯수를 리턴해주고, ‘ __getitem__’ 에서는 파일 경로가 담긴 리스트의 인덱스값을 참조해 해당 이미지를 연 다음 tensor 자료형으로 바꾸어 이미지 전처리를 실행하는 구조이다. Iterable-style dataset - random으로 읽기에 어렵거나 data따라 batch size가 달라지는 데이터에 적합하다..
2021.08.01 -
컴퓨터구조 1, 2강
※ http://kocw.net/home/cview.do?mty=p&kemId=1388791 영남대학교 최규상 교수님의 KOCW강의를 듣고 작성한 글입니다. ※ Performance의 정의 computer technoloogy의 발전 Moore's Law Makes novel applications feasible computers in automobiles cell phones human genome project world wide web search engines computers are pervasive(만연한) Moore's Law 하나의 칩에 들어갈 수 있는 트랜지스터의 개수는 매 2년마다 2배씩 늘어날 것이다 → 실제로는 더 빨리 더 많이 증가하였다 (log Scale로) ⇒ 무어의 법칙이 ..
2021.07.30 -
[Pytorch] model.eval()
Pytorch로 구현된 딥러닝모델 코드들을 보면 자주 볼 수 있다 (저는 cyclegan 코드리뷰 중 궁금해졌습니다.) def sample_images(batches_done): """Saves a generated sample from the test set""" imgs = next(iter(val_dataloader)) G_AB.eval() G_BA.eval() real_A = Variable(imgs["A"].type(Tensor)) fake_B = G_AB(real_A) real_B = Variable(imgs["B"].type(Tensor)) fake_A = G_BA(real_B) ... ... nn.Module에서 train time과 eval time에서 수행하는 다른 작업을 수행할 수 있..
2021.07.27 -
[Python] __call__함수
파이썬은 __(double underscore)로 시작하는 magic method로 클래스가 특별한 동작을 수행하게 할 수 있음 함수호출처럼 클래스의 객체도 호출할 수 있게 만들어주려면 __call__이라는 매직매소드 필요 callable함수를 통해 호출가능한 객체인지 확인할 수 있다. (활용 예) 출처 : https://github.com/rosinality/style-based-gan-pytorch/blob/master/model.py class EqualLR: def __init__(self, name): self.name = name def compute_weight(self, module): weight = getattr(module, self.name + '_orig') fan_in = wei..
2021.07.26 -
[Pytorch] torch.nn.Parameter
arameter로 간주되는 tensor의 일종 Parameters는 class = torch.Tensor의 subclasses Module class와 함께하면 특별한 속성을 가진다 Module Attributes가 할당되면 자동으로 Module의 parameter들의 list로 추가되고 Module.Parameters iterator에 추가 된다. =>Tensor 할당과 다른 효과 e.i. RNN의 last hidden state같은 일부 임시상태를 모델에 cache하려고 할 수 있기 때문 Parameter같은 class가 없다면 이러한 임시적인 것들도 등록되어버릴것이다. ex) def __init__(self, input_size, hidden_size, correlation_func=1, do_si..
2021.07.26 -
[python] *args , **kwargs
- *args *arguments의 줄임말. = 꼭 이렇게 쓸 필요는 없다. *a, *names등등 다 가능 여러개의 인자를 받고자 할 때 쓰임 일반 변수보다는 뒤에 위치하도록 해야함. 그렇지 않으면 오류가 난다. ex. 학생 이름들을 인자로 받고 싶어요! def print_names(*names): for name in names: print(name) print('names: ', names, 'type:', type(names)) if __name__ == '__main__': print_names('홍길동', '김철수') 여러 인자가 튜플 형태로 들어와서 출력된다! - **kwargs keyword argument의 줄임말 키워드 = 특정값 형태로 함수호출 가능 이렇게 들어온 인자는 딕셔너리 형태..
2021.07.19