일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- Selenium
- Numpy
- SSH
- ubuntu
- 컨테이너
- error
- Docker
- 핑거스타일
- 프로그래머스
- windows forms
- C++
- mysql
- C#
- 기타 연주
- Visual Studio
- YOLO
- OpenCV
- pandas
- VS Code
- paramiko
- 채보
- JSON
- Python
- 오류
- label
- C
- pytorch
- nvidia-smi
- pip
- Linux
- Today
- Total
목록pytorch (11)
기계는 거짓말하지 않는다
Windows 환경에서 multiprocessing(DataLoader의 num_workers>0)이 내부적으로 프로세스를spawn(push)할 때 발생 할 수 있는 오류의 예이다.EOFError: Ran out of input...ForkingPickler(file, protocol).dump(obj)_pickle.PicklingError: Can't pickle at 0x0000029A93FCF820>: attribute lookup on __main__ failed익명 함수(lambda)나 로컬 함수 등 피클로 직렬화할 수 없는 객체를 읽어 들이려 하기 때문이다num_workers=0으로 설정하면 해결은 되지만 여러 workers를 사용하여 데이터를 읽으려 할 때는 이렇게 할 수 없다.아래는 W..
딥러닝 실험을 할 때, 결과의 재현성은 매우 중요하다. 실험의 일관성을 유지하기 위해서는 동일한 조건에서 실험을 반복할 수 있어야 한다. 이를 위해 랜덤 시드를 고정하는 방법을 사용할 수 있고, 아래는 랜덤 시드를 고정하는 함수와 모델을 로드하는 예시이다.import torchimport randomimport numpy as npdef set_seed(seed=42): random.seed(seed) # random module 시드 고정 np.random.seed(seed) # numpy 랜덤 시드 고정 torch.manual_seed(seed) # PyTorch CPU 랜덤 시드 고정 torch.cuda.manual_seed_all(seed) # 멀티 GPU 환경 동일..
PyTorch의 forward() 연산 방식은 기본적으로 순차적으로 실행되는 것처럼 보이지만, 내부적으로 가능한 연산을 병렬로 실행한다. 특히 GPU에서는 연산이 비동기적으로 수행될 수 있고병렬 처리를 더욱 효율적으로 활용할 수 있다.연산 그래프PyTorch에서 forward() 실행 시 생성되는 연산 그래프(Computation Graph)는동적 방식(Dynamic Computation Graph)으로 작동한다.이는 모델의 forward pass 과정에서 연산이 발생할 때마다 그래프가 즉시 생성되는 방식이다.연산 그래프의 특징동적 생성(Dynamic Graph)TensorFlow의 정적 그래프(Static Graph)와 달리, PyTorch는 실행 시점에서 그래프를 즉시 생성한다.따라서 모델 구조를 유..
Creating a tensor from a list of numpy.ndarrays is extremely slow.Please consider converting the list to a single numpy.ndarray with numpy.array()before converting to a tensor.PyTorch에서 List에 다수의 numpy.ndarray가 있을 경우 torch.tensor로 변환하는 경우 발생한다.이렇게 하면 성능이 저하될 수 있고, List를 단일 numpy.ndarray로 변환 후 tensor로 다시 변환하여야 한다.import numpy as npimport torchdef convert_to_tensor(list_of_arrays): # 리스트를 numpy..
PyTorch 모델 사용 시, 입력 텐서와 가중치 텐서의 데이터 유형이 서로 일치하지 않을 때 발생할 수 있는 오류이다.아래는 오류 내용들이다. RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensorRuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same ~ to() method를 이용해 같은 데이터 유형으로 만들어주면 된다...

PyTorch를 이용한 Multiclass ClassificationCustom Datafeature 5개, label 종류 6개로 이루어진 데이터.각 label마다 기본 base 값을 토대로 무작위로 생성 (Total 1200개)import pandas as pddataFrame = pd.read_csv("custom_random_data.csv", delimiter=",");# label 종류 별 feature 표준편차 확인print(dataFrame.groupby("Name").std())표준편차가 큰 F3 feature를 제외한 나머지로 학습을 진행Custom Dataset, Custom Modelclass CustomDataset(Dataset): def __init__(self, data..
이미지 Augmentation을 할 때 사용할 수 있다.Augmentation은 데이터의 양을 늘리기 위해 원본에 각종 변환을 적용하고 데이터를 늘릴 수 있다.동일한 이미지들을 조금씩 변형시켜가며 학습하면서 Overfitting을 방지하는 데 도움이 된다.학습 용도에 맞는 augmentation을 선택해서 사용하여야 한다.보통 Training 단계에서 많이 사용되지만 Test 단계에서도 사용이 가능하며,이를 Test Time-Augmentation(TTA)이라고 함Dataloader를 이용하여 받으면 channel, height, width(c, h, w) shape가 되며img.cpu().numpy().transpose(1, 2, 0).copy()를 이용하면 OpenCV에서 사용할 수 있는 (h, w,..
PyTorch는 torch.utils.data.Dataset과 torch.utils.data.DataLoader의 두 가지 데이터셋 라이브러리를 제공하며미리 준비된(pre-loaded) 데이터셋 뿐 아니라 가지고 있는 데이터를 사용할 수 있다.Dataset은 data와 label을 저장한다.DataLoader는 Dataset에 쉽게 접근할 수 있도록 iterable 객체로 만들어 주고sampler, shuffle, batch_size 등 다양한 매개변수를 설정 할 수 있다.from torch.utils.data import Datasetfrom torch.utils.data import DataLoaderclass CustomDataset(Dataset): def __init__(self, data..