def compute_features_images_folder(self):
        if self.model is None:
            raise Exception("No model is defined")
        else:
            folder = os.path.join(
                Path(os.path.dirname(__file__)).parent, self.folder_path)
            files_in_directory = misc.get_images_in_directory(folder)
            features_image_folder = []
            for file, path in tqdm(files_in_directory.items()):
                image_feature = self.compute_image_features(path,
                                                            print_arr=False)
                features_image_folder.append(image_feature)
            images = list(files_in_directory.keys())
            folder_images_features_dict = {}
            for i in range(len(images)):
                folder_images_features_dict[
                    images[i]] = features_image_folder[i]

            # print(folder_images_features_dict)

            if self.model_name == 'SIFT':
                misc.save2pickle(folder_images_features_dict,
                                 os.path.dirname(__file__),
                                 feature=self.model_name + "_OLD")
                folder_images_features_dict_sift_new = self.compute_sift_new_features(
                    folder_images_features_dict)
                misc.save2pickle(folder_images_features_dict_sift_new,
                                 os.path.dirname(__file__),
                                 feature=self.model_name)
            else:
                misc.save2pickle(folder_images_features_dict,
                                 os.path.dirname(__file__),
                                 feature=self.model_name)
Пример #2
0
 def get_features(self, label):
     test_dataset_folder_path = os.path.abspath(
         os.path.join(Path(os.getcwd()).parent, self.labelled_dataset_path))
     images_list = list(
         misc.get_images_in_directory(test_dataset_folder_path).keys())
     metadata = Metadata(images_list)
     if self.feature_name != 'SIFT':
         metadata.save_label_decomposed_features(label,
                                                 self.decomposed_feature)
         features = misc.load_from_pickle(
             self.reduced_pickle_file_folder,
             self.decomposed_feature + '_' + label)
     else:
         features = {}
         database_features = misc.load_from_pickle(
             self.main_pickle_file_folder, self.feature_name)
         label_images_list = metadata.get_specific_metadata_images_list(
             feature_dict={'aspectOfHand': label})
         for image in label_images_list:
             features[image] = database_features[image]
     return features
Пример #3
0
    def get_unlabelled_images_decomposed_features(self):
        test_dataset_folder_path = os.path.abspath(
            os.path.join(
                Path(os.getcwd()).parent, self.unlabelled_dataset_path))
        images_list = list(
            misc.get_images_in_directory(test_dataset_folder_path).keys())
        images_decomposed_features = {}

        for image_id in images_list:
            features_images = FeaturesImages(self.feature_name,
                                             test_dataset_folder_path)
            test_image_path = os.path.join(test_dataset_folder_path, image_id)
            test_image_features = list()
            test_image_features.append(
                features_images.compute_image_features(test_image_path))
            if self.decomposition_name != '':
                decomposed_features = self.decomposition.decomposition_model.get_new_image_features_in_latent_space(
                    test_image_features)
                images_decomposed_features[image_id] = decomposed_features
            else:
                images_decomposed_features[image_id] = test_image_features

        return images_decomposed_features
    m = int(input("Please specify the value of m: "))
    decomposition = Decomposition(decomposition_model, k, model,
                                  test_dataset_path)
    similarity = Similarity(model, image_id, m)
    similarity.get_similar_images(test_dataset_path,
                                  decomposition,
                                  reduced_dimension=True)

elif task == '3':
    model = input("1.CM\n2.LBP\n3.HOG\n4.SIFT\nSelect model: ")
    decomposition_model = input(
        "1.PCA\n2.SVD\n3.NMF\n4.LDA\nSelect decomposition: ")
    test_dataset_folder_path = os.path.abspath(
        os.path.join(Path(os.getcwd()).parent, test_dataset_path))
    images_list = list(
        misc.get_images_in_directory(test_dataset_folder_path).keys())
    metadata = Metadata(images_list)
    label = int(
        input("1.Left-Hand\n2.Right-Hand\n3.Dorsal\n4.Palmar\n"
              "5.With accessories\n6.Without accessories\n7.Male\n8.Female\n"
              "Please choose an option: "))
    label_interpret_dict = {
        1: {
            "aspectOfHand": "left"
        },
        2: {
            "aspectOfHand": "right"
        },
        3: {
            "aspectOfHand": "dorsal"
        },
Пример #5
0
def get_images_list(folder_path):
    folder = os.path.join(Path(os.path.dirname(__file__)).parent, folder_path)
    return misc.get_images_in_directory(folder)
Пример #6
0
        
    return class_labels 

    
labelled_set_path = input("Enter the path for labelled input set - ")
unlabelled_set_path = input("Enter the path for unlabelled input set - ")
metadata_file_path = input("Enter the path for metadata csv - ")
metadata_file_name = input("Enter the name for labelled metadata csv - ")
unlabelled_metadata_file_name = metadata_file_name

# unlabelled_metadata_file_name = input("Enter the name for unlabelled metadata csv - ")
metadata_df = pd.read_csv(metadata_file_path+'/'+metadata_file_name)
unlabelled_metadata_df = pd.read_csv(metadata_file_path+'/'+unlabelled_metadata_file_name)

# print(metadata_df)
unlabelled_images_list = list(misc.get_images_in_directory(unlabelled_set_path).keys())



reduced_pickle_file_folder =  os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pickle_files')
classifier = input("Choose the Classifier - \n. 1. SVM \n. 2. Decision Tree \n. 3. PPR Classifier \n. 4. Exit \n. ")


def svm():
    model = "HOG"
    decomposition_model = "PCA"
    phase = input("Choose from \n. 1. Train \n. 2. Test \n.")
    if (phase == "train"):
        # phase = "train"
        training_features,images_list = test.compute_features_folder(labelled_set_path, phase)