Moonss
Moon's
Moonss
전체 방문자
오늘
어제
  • 분류 전체보기 (24)
    • 환경 설정 (2)
    • git 사용법 (2)
    • Pandas (1)
    • 알고리즘 (7)
    • Pytorch (4)
    • GCP 환경 설정 (1)
    • cs231n (0)
    • Error (1)
    • 데이터 분석 (1)
    • 작성 전 글 저장 (0)

블로그 메뉴

  • ABOUT
  • POST
  • GUEST BOOK

공지사항

인기 글

태그

  • git config global --unset
  • 알고리즘
  • git config --global
  • 환경설정
  • ifconfig
  • github
  • Blender
  • Linux
  • BIG-O
  • Linux OS
  • Python
  • user.email
  • GPU
  • 가상환경
  • error
  • git config --unset
  • git init
  • git
  • 3d
  • user.name
  • gcp
  • IP
  • git config

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Moonss

Moon's

Pytorch

torchvision.transforms 함수

2022. 11. 19. 18:51

Torchvision transforms

Torchvision transforms import 

import torchvision.transforms as transforms

Torchvision transforms Compose

# Composes several transforms together  

transform = transforms.Compose([
				transforms.ToTensor(),
				transforms.Resize(224),
				transforms.Normalize((0.5,), (0.5,))])

 

-. transforms.Compose 함수는 여러 단계로 transforms 하기 위해 사용한다. 

-. trochvision.transforms에서 transforms 함수의 종류들 : https://pytorch.org/vision/stable/transforms.html


# 개인적으로 많이 사용하는 Transforms 함수 정리 

transforms.ToTensor() 

# convert a PIL or numpy.ndarray to tensor, This transform does not support torchscript 

# Converts a PIL Image or numpy.ndarray (H x W x C) in the range [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8

-. PIL , numpy.ndarray : (H x W x C) 범위는 [0,255] -> (Convert) torch : torch.FloatTensor (C x H x W) 범위는 [0.0, 1.0] 

-. torchscript 지원하지 않는다. -> torchscript? 모르겠다. 

transforms.ToPILImage(mode = None) 

# Convert a tensor or an ndarray to PIL Image. This transform does not support torchscript.

# Converts a torch.*Tensor of shape C x H x W or a numpy ndarray of shape H x W x C to a PIL Image while preserving the value range.

## mode (PIL.Image mode) – color space and pixel depth of input data (optional). If mode is None (default) there are some assumptions made about the input data: - If the input has 4 channels, the mode is assumed to be RGBA. - If the input has 3 channels, the mode is assumed to be RGB. - If the input has 2 channels, the mode is assumed to be LA. - If the input has 1 channel, the mode is determined by the data type (i.e int, float, short).

ToPILImage(mode)

-. ToTensor과 반대 역활 

-. Tensor :(C x H x W) 또는 numpy (H x W x C)를 범위를 보존하며 PIL로 바꾼다. 

-. 아직 직접 사용하지 못함 


transforms.Normalize(mean,std,inplace=False)

# Normalize a tensor image with mean and standard deviation. This transform does not support PIL Image. Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for n channels, this transform will normalize each channel of the input torch.*Tensor i.e., output[channel] = (input[channel] - mean[channel]) / std[channel]

##mean (sequence) – Sequence of means for each channel.

##  std (sequence) – Sequence of standard deviations for each channel.

## inplace (bool,optional) – Bool to make this operation in-place.

-. tensro image를 평균과 표준편차로 정규화 한다.

-. output[channel] = (input[channel] - mean[channel]) / std[channel]

-. 아직 inplace 기능은 잘 모르겠다. 

저작자표시 (새창열림)

'Pytorch' 카테고리의 다른 글

PyTorch - 2) 텐서(Tensor) 연산  (0) 2022.09.28
PyTorch - 1) 텐서(Tensor)  (0) 2021.12.29
PyTorch 시작하기  (0) 2021.12.28
    'Pytorch' 카테고리의 다른 글
    • PyTorch - 2) 텐서(Tensor) 연산
    • PyTorch - 1) 텐서(Tensor)
    • PyTorch 시작하기
    Moonss
    Moonss

    티스토리툴바