Obfuscation pipeline, done now extraction of metadata from obfuscated images

This commit is contained in:
2025-05-09 19:57:05 +02:00
parent 4a74738dee
commit 5b98bd0df7
7 changed files with 26 additions and 26 deletions
Binary file not shown.
+1 -1
View File
@@ -7,7 +7,7 @@ class Config:
raw_dataset_path="datasets/raw/"
filtered_output_directory="datasets/filtered/"
obfuscated_output_directory="datasets/obfuscated/"
max_images_per_dataset=500
max_images_per_dataset=1000
seg_model_type="yolo11m-seg.pt"
pose_model_type="yolo11m-pose.pt"
+6 -3
View File
@@ -87,11 +87,10 @@ from obfuscation.obfuscation_engine import ObfuscationEngine
#Detected? (Any overlapping segment?)
#Deviation? (IoU)
#TODO: Zusätzliche analysen für Journal: Konfidenz, Mehrere Modelle für Gesichtserkennung, Andere Datensets (in the wild)
def main():
#TODO: die analysen vorher/nachher
#TODO: gute techniken hinzufügen
#TODO: Techniken alle mit GPU
print("Starting obfuscation platform")
#1: Preprocess images and extract metadata
@@ -109,8 +108,12 @@ def main():
obfuscation_engine.obfuscate_datasets(Config.filtered_output_directory, Config.obfuscated_output_directory, verbose=Config.verbose)
#3: Extract metadata from obfuscated datasets
#TODO: Hier durch die obfuskierten Bilder iterieren
# if Config.tasks["analysis"]:
# image_meta = extractor.extract(img_file_path)
# meta_data_file_path = os.path.join(output_directory, os.path.basename(img_file_path).split(".")[0] + ".json")
# with open(meta_data_file_path, "w") as f:
# json.dump(image_meta.to_dict(), f, indent=2)
if __name__ == '__main__':
main()
+12 -16
View File
@@ -75,8 +75,8 @@ class MetaExtractor:
self.segmentor = YOLO(Config.seg_model_type)
self.pose_estimator = YOLO(Config.pose_model_type)
self.face_detector = DeepFace.build_model(model_name=Config.face_model_type, task="face_detector")
# self._face_backend = Config.face_model_type
# self.face_detector = DeepFace.build_model(model_name=Config.face_model_type, task="face_detector")
self._face_backend = Config.face_model_type
# MediaPipe
self._mp_mesh = mp.solutions.face_mesh.FaceMesh(static_image_mode=True, refine_landmarks=True, max_num_faces=1)
@@ -112,23 +112,19 @@ class MetaExtractor:
# -- 1) Face detection (DeepFace) --------------------------------
try:
faces = self.face_detector.detect_faces(cv2.cvtColor(person_crop, cv2.COLOR_RGB2BGR))
# print(faces)
# faces1 = DeepFace.extract_faces(
# cv2.cvtColor(person_crop, cv2.COLOR_RGB2BGR),
# detector_backend=Config.face_model_type,
# enforce_detection=True
# )
except ValueError:
# faces = self.face_detector.detect_faces(cv2.cvtColor(person_crop, cv2.COLOR_RGB2BGR))
faces = DeepFace.extract_faces(
cv2.cvtColor(person_crop, cv2.COLOR_RGB2BGR),
detector_backend=Config.face_model_type,
enforce_detection=True
)
except:
faces = []
if faces:
fx0, fy0, fx1, fy1 = _facial_region_to_xyxy(faces[0])
# print(fx0, fy0, fx1, fy1)
# fx0, fy0, fx1, fy1 = _deepface_bbox_to_xyxy(faces1[0])
# print(fx0, fy0, fx1, fy1)
# exit()
# fx0, fy0, fx1, fy1 = _facial_region_to_xyxy(faces[0])
fx0, fy0, fx1, fy1 = _deepface_bbox_to_xyxy(faces[0])
face_bbox = [fx0 + px0, fy0 + py0, fx1 + px0, fy1 + py0]
# crop the exact face for emotion / mesh
+7 -6
View File
@@ -55,16 +55,17 @@ class ObfuscationEngine:
return img
def obfuscate_datasets(self, path_to_filtered_dataset, output_path, verbose=False):
sub_dataset_folders = [os.path.join(path_to_filtered_dataset, sub_dataset_folder) for sub_dataset_folder in os.listdir(path_to_filtered_dataset)]
def obfuscate_datasets(self, path_to_filtered_datasets, output_path, verbose=False):
sub_dataset_folders = [os.path.join(path_to_filtered_datasets, sub_dataset_folder) for sub_dataset_folder in os.listdir(path_to_filtered_datasets)]
iterable = sub_dataset_folders
if verbose:
iterable = tqdm(sub_dataset_folders, desc="Obfuscating folders")
for sub_dataset_folder in iterable:
print(f"Obfuscating {sub_dataset_folder}")
image_meta_pairs = get_image_and_meta_file_paths(sub_dataset_folder)
for sub_dataset_folder_path in iterable:
print(f"Obfuscating {sub_dataset_folder_path}")
image_meta_pairs = get_image_and_meta_file_paths(sub_dataset_folder_path)
for technique in self.obfuscation_techniques:
technique_path = os.path.join(output_path, technique.name())
technique_path = os.path.join(output_path, os.path.basename(sub_dataset_folder_path), technique.name())
if not os.path.exists(technique_path):
os.makedirs(technique_path)
for image_path, meta_path in image_meta_pairs: