For all of the following, program the solution yourself. Don’t just call a library function that does the whole question for you, or you’ll get zero (no, that doesn’t mean you can’t use any library functions, but it does mean that you have to show you understand how to compute the answer yourself).
All written answers should be between 50 and 500 words. If you can describe all the necessary information in 50 words, that’s better. However, you’ll only be graded on whether you describe the necessary ideas.
TASK 0.1: You know the drill. Import Numpy and PyPlot.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D #This is for 3d scatter plots.
from matplotlib.pyplot import imread
from PIL import Image
Let’s understand the settings of datasets.
We provide you with 3 pedestrian image folders, ‘train’, ‘gallery’, and ‘val_query’. There are 199 images in ‘train’ which are used to compute the eigen pedestrians and build the projection matrix. ‘Gallery’ contains 90 images which belong to 15 different pedestrians. ‘Val_query’ has 3 images of 3 pedestrians. If two images’ file name have same first four digits, then these two images belong to same pedestrian.
In [ ]:
width = 64
height = 128
dimension = (height, width, 3)
images = 
filename = 
for file in os.listdir(“./train”):
im = imread(“./train/” + file)
im = im.flatten() # flatten im into a vector
A_pp = np.stack(images).T # build a matrix where each column is a flattened image print(A_pp.shape)
TASK 1.1: Let be a matrix of data. Each column of is a sample of data (1 example for instance). The rows of are thus the features (dimensions) of each of these samples. Complete the function , for which:
𝑄𝑖,: = 𝐴_𝑝𝑝𝑖,: − 𝜇𝑖
…where 𝜇𝑖=1/𝑚∑𝑗 𝑝𝑝𝑖?
𝐴 ∈ ℝ𝐷×N
𝑄𝑖,: is the row of 𝑄.
If the norm is 0, divide by 1 instead.
In [ ]:
# YOUR CODE HERE
A, Q_norms, A_means = preprocess(A_pp)