본문 바로가기

pytorch

Pytorch DDP (Distributed Data Parallel) 사용 관련 웹페이지 모음 1. Pytorch Tutorial [overview] https://pytorch.org/tutorials/beginner/dist_overview.html PyTorch Distributed Overview — PyTorch Tutorials 2.0.1+cu117 documentation PyTorch Distributed Overview Author: Shen Li Note View and edit this tutorial in github. This is the overview page for the torch.distributed package. The goal of this page is to categorize documents into different topics and briefly d.. 더보기
ImportError: cannot import name '_NewEmptyTensorOp' from 'torchvision.ops.misc' 해당 에러는 torchvision의 version 확인을 제대로 못해서 발생하는 문제이다. import torch import torch.nn as nn import torch.distributed as dist from torch import Tensor # needed due to empty tensor bug in pytorch and torchvision 0.5 import torchvision if float(torchvision.__version__[:3]) < 0.5: import math from torchvision.ops.misc import _NewEmptyTensorOp def _check_size_scale_factor(dim, size, scale_factor): # type: .. 더보기
Pytorch에서 meshgrid 만들기 ''' x : forward direction y : side (left) direction ''' s, b, c, h, w = seq_z.size() h_meters = self.cfg['bev']['h_meters'] w_meters = self.cfg['bev']['w_meters'] h_grid = torch.linspace(0, h_meters, h) - (h_meters / 2) w_grid = torch.linspace(0, w_meters, w) - (w_meters / 2) grid_x, grid_y = torch.meshgrid(torch.flip(h_grid, dims=(0,)), torch.flip(w_grid, dims=(0,)), indexing='ij') grid = torch.. 더보기
einops으로 pytorch의 차원관리 예제 1. rearrange # suppose we have a set of 32 images in "h w c" format (height-width-channel) >>> images = [np.random.randn(30, 40, 3) for _ in range(32)] # stack along first (batch) axis, output is a single array >>> rearrange(images, 'b h w c -> b h w c').shape (32, 30, 40, 3) # concatenate images along height (vertical axis), 960 = 32 * 30 >>> rearrange(images, 'b h w c -> (b h) w c').shape (960.. 더보기
RTX 3090 을 지원하는 pytorch anaconda로 설치하기 anaconda에서 바로 pytorch를 설치하면 deep learning 모델 학습 시 다음과 같은 error message가 나올 수 있다. $ CUDA error: no kernel image is available for execution on the device 이때 아래와 같은 방식으로 설치를 하자. 1. anaconda 환경을 만든다. (python 3.8이상) $ conda create -y -n example python=3.8 2. pytorch를 pip로 설치한다. $ pip install torch==1.11+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html 더보기
Gaussian, LogGaussian PDF in Pytorch def GaussianPDF(mean, logvar, z): r""" Return the PDF value of z in N(mean,exp(logvar)) mean, logvar : [*, dim_z] z : [*, N, dim_z] return: [*, N, dim_z] """ if type(mean) is torch.Tensor: mean, logvar = mean.unsqueeze(-2), logvar.unsqueeze(-2) return 1/(np.sqrt(2*np.pi)*torch.exp(logvar*0.5)) * torch.exp(-((z-mean)**2) / (2*torch.exp(logvar))) elif type(mean) is np.ndarray: mean, logvar = np.ex.. 더보기
Implement KL Divergence using Pytorch def GaussianPDF(mean, logvar, z): r""" Return the PDF value of z in N(mean,exp(logvar)) mean, logvar : [*, dim_z] z : [*, N, dim_z] return: [*, N, dim_z] """ if type(mean) is torch.Tensor: mean, logvar = mean.unsqueeze(-2), logvar.unsqueeze(-2) return 1/(np.sqrt(2*np.pi)*torch.exp(logvar*0.5)) * torch.exp(-((z-mean)**2) / (2*torch.exp(logvar))) elif type(mean) is np.ndarray: mean, logvar = np.ex.. 더보기