Hexo

  • Home

  • Archives

Pytorch Notes

Posted on 2019-09-12

Pytorch Notes

This notes mostly comes from source code from pytorch just to summarize the most import part of those most frequently used functions.

torchvision

transforms

..ToTensor()

torchvision.tansforms.functional(pic): Convert a PIL Image or numpy.ndarray to tensor.

1
2
3
4
5
6
# This will divide image pixel value by 255.0 to normalize it into [0, 1.0]
img = img.transpose(0, 1).transpose(0, 2).contiguous()
if isinstance(img, torch.ByteTensor):
return img.float().div(255)
else:
return img

..Normalize()

Using *.*.functional.normalize() function: Normalize a tensor image with mean and standare deviation:

1
2
3
mean = torch.as_tensor(mean, dtype=dtype, device=tensor.device)
std = torch.as_tensor(std, dtype=dtype, device=tensor.device)
tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
Hello World
CPP Primer Chapter 5 Statements
  • Table of Contents
  • Overview

Zepyhrus

12 posts
  1. 1. Pytorch Notes
    1. 1.1. torchvision
      1. 1.1.1. transforms
        1. 1.1.1.1. ..ToTensor()
        2. 1.1.1.2. ..Normalize()
© 2020 Zepyhrus
Powered by Hexo v3.9.0
|
Theme – NexT.Mist v7.3.0