1. 이미지를 Load 한다. 2. 이미지를 Resize 한다. 3. (모델이 요구하는 인풋 텐서의 컬러 포맷이 RGB인 경우) 이미지의 컬러 포맷을 RGB로 변환한다. *OpenCV는 기본적으로 BGR 포맷으로 이미지를 처리한다. 4. 이미지를 텐서(torch::Tensor 형)로 변환한다. 5. 모델이 요구하는 인풋 텐서의 Shape에 맞도록 텐서를 Reshape한다. (본 예제에서는 NCHW 포맷을 따름) 6. 텐서를 정규화한다. 7. (GPU를 사용하는 경우) 텐서를 GPU 메모리로 업로드한다. cv::Mat img_bgr_u8 = cv::imread("your_image.jpg",cv::IMREAD_COLOR); cv::Mat img_rgb_u8; //resize cv::resize(img_bg..
import torch import torch.nn as nn class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.conv1 = nn.Conv2d(3, 16, 3, 1, 1) self.bn1 = nn.BatchNorm2d(16) self.conv2 = nn.Conv2d(16, 16, 3, 1, 1) self.bn2 = nn.BatchNorm2d(16) def forward(self, x): x = torch.relu(self.bn1(self.conv1(x))) x = x + torch.relu(self.bn2(self.conv2(x))) return x input = torch.randn((1, 3, 736, 128..
github.com/pytorch/pytorch/blob/master/torch/nn/modules/conv.py pytorch/pytorch Tensors and Dynamic neural networks in Python with strong GPU acceleration - pytorch/pytorch github.com 위 파일에서 reset_parameters() 함수를 보면 됨.
github.com/pytorch/pytorch/issues/1917 Get a single batch from DataLoader without iterating · Issue #1917 · pytorch/pytorch Is it possible to get a single batch from a DataLoader? Currently, I setup a for loop and return a batch manually. If there isn't a way to do this with the DataLoader currently, I would be happ... github.com dataloader_iterator = iter(dataloader) for i in range(iterations):..
모델을 구성하는 레이어(혹은 연산) 중 torch.exp 를 포함하는 경우 auto mixed precision과 충돌이 발생할 수 있습니다. 이는 torch.exp의 output data type이 auto mixed precision과 호환되도록 자동으로 변환되지 않아 발생하는 문제입니다. (추후 업데이트에서 해결될 문제로 보이긴 합니다.) 이런 경우 torch.exp 의 output의 data type을 입력 텐서 x의 data type으로 재변환시키는 과정이 필요합니다. output = torch.exp(x).type(x.dtype)
일반적으로 Depthwise Convolutional Layer는 CNN 모델의 연산량과 파라미터 수를 줄이기 위하여 제안되었으나, 실제로 이를 사용하여 모델을 구현한 뒤에 속도를 측정해보면 줄어드는 연산량 대비 고속화의 정도가 크지 않습니다. 특히, 저의 경우 Depthwise Convolutional Layer가 포함된 CNN 모델을 학습시키려하니, Forward 및 Backward 과정에서 비정상적으로 긴 시간이 걸리는 것을 확인하였습니다. 이러한 경우 코드상에서 Forward 및 Backward 과정 이전에 아래의 코드를 작성해주면 소요시간을 단축시킬 수 있습니다. torch.backends.cudnn.deterministic = False torch.backends.cudnn.benchmark ..
def img2tensor(img): #the format of img needs to be bgr format img = img[..., ::-1] #bgr2rgb img = img.transpose(2, 0, 1) #(H, W, CH) -> (CH, H, W) img = np.ascontiguousarray(img) tensor = torch.tensor(img, dtype=torch.float32) return tensor
본 게시글은 해당 링크를 참고하여 작성된 게시글입니다. Multi GPUs를 사용하여 Model을 학습시키고 Weights을 저장하면 모든 Parameter의 Key값에 "module."이 붙은채로 저장됩니다. 그런데, 이렇게 되면 Model의 멤버 변수(self.*)를 클래스 외부에서 접근할때 코딩 시 객체명.* 으로 접근하지 못하고 객체명.module.*과 같이 "module"을 붙여주어야 접근이 가능해집니다. 이렇게 되면, 코드를 작성할때 항상 module의 존재를 신경써주어야 합니다. 문제를 파악해봅시다. module이 붙는 이유는 Model을 병렬화 시켰기 때문이고, Model을 병렬화 시켰던 이유는 Load하고자하는 Weights의 Key값에 'module.'이 붙었기 때문입니다. 해결 방법은..
- Total
- Today
- Yesterday
- 자료구조
- 백준
- 순열
- FairMOT
- 파이참
- PyCharm
- 단축키
- 가장 긴 증가하는 부분 수열
- 인공지능을 위한 선형대수
- 백준 11437
- LCA
- 백트래킹
- Lowest Common Ancestor
- 위상 정렬 알고리즘
- C++ Deploy
- MOT
- 백준 1766
- 조합
- 이분탐색
- 백준 11053
- ㅂ
- cosine
- 문제집
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |