face_recognition version: '1.2.3' Python version: 3.11 Operating System: Windows 11
Description For organization purposes i have my functions inside a myfunctionsfolder/module so i can import them from there. But somehow when importing the library it just gets stuck and doesnt raise an exception even. Other functions in the module do work and when i comment out the import for face_recognition the module starts working again. When i copy the exact function script to my main folder so out of the module it works again just fine. Even more weird is that it somehow does work for like one or two face_locations as an example before getting stuck.
try:
import time
import inspect
import face_recognition
from termcolor import colored
def find_facelocations_aug(image, file_path, num_up):
# Get the current function's name for error printing
func_name = inspect.currentframe().f_code.co_name
# Initialize counters with dynamic keys
counters = {
f'{func_name}_errors_loading': 0,
f'{func_name}_exceptions': 0,
'skipped_images': 0,
f'{func_name}_time_elapsed': 0.0
}
try:
if image is not None:
start_time = time.time() # Start timing
# Use face_recognition to locate faces and get encodings
face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=1, model="hog")
# Calculate elapsed time and add to counters
elapsed_time = time.time() - start_time
counters[f'{func_name}_time_elapsed'] = elapsed_time
if len(face_locations) == 1:
return face_locations, counters
else:
print(colored(f" No or multiple faces found for {file_path} in {func_name.capitalize()}", 'yellow'))
counters['skipped_images'] += 1
return None, counters
else:
print(colored(f" Error loading image for {file_path} in {func_name.capitalize()}", 'red'))
counters['skipped_images'] += 1
counters[f'{func_name}_errors_loading'] += 1
return None, counters
except Exception as e:
print(colored(f"{func_name.capitalize()} failed for {file_path}: {e}", 'red'))
counters['skipped_images'] += 1
counters[f'{func_name}_exceptions'] += 1
return None, counters
except Exception as e:
print(colored(f"An error occured while importing: {e}", 'red'))
What I Did I have tried eveything i could think of before realising it is because of the import. And since i have tried preloading it in my main script but i just cant think of other possible resolutions