def produce_15_hist(): # These modules are imported locally as Matplotlib is a headache and takes time to import import os import matplotlib.pyplot as plt all_paths = [os.path.join("data/sift/train",i) for i in os.listdir("data/sift/train")] for pu in all_paths: train_imagepaths, train_labels = sub_sample_images(pu, n_sample=50) print(pu) label_pu = os.path.basename(pu) train_image_feats = get_bags_of_sifts(train_imagepaths, kmeans) sm = np.sum(train_image_feats,axis=0) plt.hist(sm,50) plt.tick_params( axis='x', # changes apply to the x-axis which='both', # both major and minor ticks are affected bottom=False, # ticks along the bottom edge are off top=False, # ticks along the top edge are off labelbottom=False) # labels along the bottom edge are off plt.title(label_pu) plt.savefig(os.path.join(r"C:\Users\User\Desktop\figs",label_pu)) plt.clf()
if a[2] not in categories: categories.append(a[2]) print("Categories: ", categories) ''' Step 1: Represent each image with the appropriate feature Each function to construct features should return an N x d matrix, where N is the number of paths passed to the function and d is the dimensionality of each image representation. See the starter code for each function for more details. ''' print('Extracting SIFT features\n') #TODO: You code build_vocabulary function in util.py voc_size = 50 kmeans = build_vocabulary(train_image_paths, vocab_size=voc_size) #TODO: You code get_bags_of_sifts function in util.py train_image_feats = get_bags_of_sifts(train_image_paths, kmeans) test_image_feats = get_bags_of_sifts(test_image_paths, kmeans) #If you want to avoid recomputing the features while debugging the #classifiers, you can either 'save' and 'load' the extracted features #to/from a file. #np.save('train_image_feats', train_image_feats) #np.save('test_image_feats', test_image_feats) #train_image_feats = np.load('train_image_feats.npy') #test_image_feats = np.load('test_image_feats.npy') make_avg_histogram(train_labels, train_image_feats, categories) ''' Step 2: Classify each test image by training and using the appropriate classifier Each function to classify test features will return an N x l cell array,