def get_image_tensor(self): image_path = self.data_dict['path'] face_finder = FaceRecognizer() face_finder.new_image(image_path) np_tensor = np.zeros(DataInterpreter.num_pixels) try: np_tensor = face_finder.get_face_1D_numpy() except (AssertionError, FileNotFoundError) as e: pass return torch.from_numpy(np_tensor).double()
def get_image_and_name_tensor(self): np_tensor = np.zeros(DataInterpreter.num_pixels + 6) image_path = self.data_dict['path'] face_finder = FaceRecognizer() face_finder.new_image(image_path) np_face_tensor = np.zeros(DataInterpreter.num_pixels) try: np_face_tensor = face_finder.get_face_1D_numpy() except AssertionError: pass assert np_face_tensor.size < np_tensor.size ctr = 0 for i in range(np_face_tensor.size): np_tensor[i] = np_face_tensor[i] ctr += 1 name = "" try: name = self.data_dict['name'] if name == None or name == "": raise NameError if " " in name: name = name[:name.index(" ")] first_letter = DataInterpreter.hash_str(name[0]) first_two = DataInterpreter.hash_str(name[1]) first_three = DataInterpreter.hash_str(name[2]) last_three = DataInterpreter.hash_str(name[-3]) last_two = DataInterpreter.hash_str(name[-2]) last_letter = DataInterpreter.hash_str(name[-1]) np_tensor[ctr] = first_letter np_tensor[ctr + 1] = first_two np_tensor[ctr + 2] = first_three np_tensor[ctr + 3] = last_three np_tensor[ctr + 4] = last_two np_tensor[ctr + 5] = last_letter except NameError: np_tensor[ctr] = 0 np_tensor[ctr + 1] = 0 np_tensor[ctr + 2] = 0 np_tensor[ctr + 3] = 0 np_tensor[ctr + 4] = 0 np_tensor[ctr + 5] = 0 return torch.from_numpy(np_tensor).double()