def identify(self,test_img): """Find the best match from the test set to the provided image.""" norm_test = test_img.flat - self.data_mean test_coeffs = N.dot(self.utt,norm_test) diff2 = ((self.proj_c - test_coeffs)**2).sum(axis=1) minidx = diff2.argmin() best_err = diff2[minidx] imshow2(test_img,self.image_coll.images[minidx], labels = ('Test Image','Best Match: %d' % minidx)) P.title('L2 error: %.2e' % best_err)
def identify(self, test_img): """Find the best match from the test set to the provided image.""" norm_test = test_img.flat - self.data_mean test_coeffs = N.dot(self.utt, norm_test) diff2 = ((self.proj_c - test_coeffs)**2).sum(axis=1) minidx = diff2.argmin() best_err = diff2[minidx] imshow2(test_img, self.image_coll.images[minidx], labels=('Test Image', 'Best Match: %d' % minidx)) P.title('L2 error: %.2e' % best_err)
def verify(test_img, key): """Verify visually that a provided image corresponds to a specified image in the training set. Two images, the provided test image and the training image 'key', are displayed side-by-side, along with the l2-norm error. Based on this information, the user can visually verify that they are the same.""" ref_coeffs = proj_c[key] norm_test = test_img.flat - data_mean test_coeffs = N.dot(utt, norm_test) l2_err = N.linalg.norm(test_coeffs - ref_coeffs, 2) imshow2(imtrain[key], test_img, labels=('Reference Image', 'Test Image')) P.title('L2 coefficient error: %.2e' % l2_err)
def verify(test_img,key): """Verify visually that a provided image corresponds to a specified image in the training set. Two images, the provided test image and the training image 'key', are displayed side-by-side, along with the l2-norm error. Based on this information, the user can visually verify that they are the same.""" ref_coeffs = proj_c[key] norm_test = test_img.flat - data_mean test_coeffs = N.dot(utt,norm_test) l2_err = N.linalg.norm(test_coeffs-ref_coeffs,2) imshow2(imtrain[key],test_img, labels = ('Reference Image','Test Image')) P.title('L2 coefficient error: %.2e' % l2_err)
def identify(test_img): """Try to find a match for test_img from the training set.""" # Normalise data, compute projections into eigenspace norm_test = test_img.flat - data_mean test_coeffs = N.dot(utt,norm_test) # Find closest match diff2 = ((proj_c - test_coeffs)**2).sum(axis=1) minidx = diff2.argmin() best_err = diff2[minidx] # Display the matching face imshow2(test_img,imtrain.images[minidx], labels = ('Test Image','Best Match: %d' % minidx)) P.title('L2 coefficient error: %.2e' % best_err)
def identify(test_img): """Try to find a match for test_img from the training set.""" # Normalise data, compute projections into eigenspace norm_test = test_img.flat - data_mean test_coeffs = N.dot(utt, norm_test) # Find closest match diff2 = ((proj_c - test_coeffs)**2).sum(axis=1) minidx = diff2.argmin() best_err = diff2[minidx] # Display the matching face imshow2(test_img, imtrain.images[minidx], labels=('Test Image', 'Best Match: %d' % minidx)) P.title('L2 coefficient error: %.2e' % best_err)
def identify(test_img): """Try to find a match for test_img from the training set.""" # Normalise data, compute projections into eigenspace XXX # Find closest match diff2 = ((proj_c - test_coeffs)**2).sum(axis=1) # this is correct. minidx = # XXX Find the index of the minimum in diff2 (look for the argmin # method) best_err = # XXX And read the actual value off diff2 using this index: # Display the matching face imshow2(test_img,imtrain.images[minidx], labels = ('Test Image','Best Match: %d' % minidx)) P.title('L2 coefficient error: %.2e' % best_err)
def verify(test_img,key): """Verify visually that a provided image corresponds to a specified image in the training set. Two images, the provided test image and the training image 'key', are displayed side-by-side, along with the l2-norm error. Based on this information, the user can visually verify that they are the same.""" # Compute the L2 error between the coefficients of the reference image: ref_coeffs = proj_c[key] # and the coefficients for your test image, which you must first normalize # by removing data_mean from the flattened version of test_img: norm_test = # XXX test_coeffs = # XXX l2_err = # XXX Look at N.linalg.norm for L2 vector norms imshow2(imtrain[key],test_img, labels = ('Reference Image','Test Image')) P.title('L2 coefficient error: %.2e' % l2_err)