in sample-apps/custom-model/code/application.py [0:0]
def preprocess(self, img):
"""Resizes and normalizes a frame of video."""
resized = cv2.resize(img, (HEIGHT, WIDTH))
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
img = resized.astype(np.float32) / 255.
img_a = img[:, :, 0]
img_b = img[:, :, 1]
img_c = img[:, :, 2]
# Normalize data in each channel
img_a = (img_a - mean[0]) / std[0]
img_b = (img_b - mean[1]) / std[1]
img_c = (img_c - mean[2]) / std[2]
# Put the channels back together
x1 = [[[], [], []]]
x1[0][0] = img_a
x1[0][1] = img_b
x1[0][2] = img_c
return np.asarray(x1)