I am new to ML/DL in general and have a fairly basic question.
The Jetson nano comes with a sample - “classification_interactive.ipynb”. In the “Live Execution” stage of the setup, there is a call to a local package called utils that exports one function - preprocess().
I understand that this function converts a PIL/numpy image to a tensor and assigns it to the cuda(GPU) device. But before it returns the image, it performs one more operation on the tensor:
image.sub_(mean[:, None, None]).div_(std[:, None, None])
What is the purpose of subtracting the mean and dividing the Std.Deviation from the tensor?
The library code is:
import torch
import torchvision.transforms as transforms
import torch.nn.functional as F
import cv2
import PIL.Image
import numpy as np
mean = torch.Tensor([0.485, 0.456, 0.406]).cuda()
std = torch.Tensor([0.229, 0.224, 0.225]).cuda()
def preprocess(image):
device = torch.device(‘cuda’)
image = PIL.Image.fromarray(image)
image = transforms.functional.to_tensor(image).to(device)
image.sub_(mean[:, None, None]).div_(std[:, None, None])
return image[None, …]