Files
obfuscation_platform/project/main.py
T

122 lines
5.7 KiB
Python

import os
from config import Config
from data_loader import DatasetLoader
from image_preprocessor import DataPreprocessor
from obfuscation.obfuscation_engine import ObfuscationEngine
##Steps:
#Configure Pipeline (e.g. region, datasets, amount of images per dataset, analysis scopes)
#For each obfuscation method
##For each dataset
###Load raw data (image-wise)
###Preprocess data and save (according to given criteria)
###Analyze data (values before obfuscation)
###Obfuscate data (with current method)
###Analyze data (values after obfuscation)
###Evaluate (analyze e.g. delta/error for before vs after, and aggregate results)
###Visualize Statistics
##Motivation
#Bilder und Videos sind daten, welche viele semantische informationen in sich tragen können
#Entsprechend ist CV so beliebt, weil sich damit mannigfaltig viele aufgaben erledigen lassen wie A, B, C
#Neben den Informationen die für die aufgabe relevant sind, auch andere Informationen abgebildet sind.
#Die ist besonders dann problematisch, wenn beispielsweise person erkennbar abgebildet sind und bilder möglicherweise veröffentlich werden sollen.
#Entsprechend gibt es die möglichkeit, bilder nachträglich zu bearbeiten um die person zu anonymisieren.
#Typischerweise wird dabei eine Verschleierung des Gesichts vorgenommen.
#VERSCHLEIERUNG NICHT GUT - MACHT NATÜRLICHKEIT des Bildes kaputt
#NATÜRLICHKEIT IST SCHWER MESSBAR
#IMPACT AUF TECHNISCHE NUTZBARKEIT NACH VERSCHLEIERUNG
#EINERSEITS STARKE LOKALE ABWEICHUNGEN
#GESICHT KÖNNTE NICHT IDENTIFIZIERBAR SEIN
#HOWEVER DURCH TECHNIK WIE SCHWARZEN BALKEN KÖNNTE ÜBERHAUPT KEIN GESICHT ZU SEHEN SEIN
#ANDERERSEITS ES KÖNNTE GESICHT DA SEIN, ABER XXX INFORMATIONEN WIE EMOTION ODER
#ODER AUCH AUF REESTLICHEN KÖRPER KÖRPER
#IN DIESEM PAPER WOLLEN WIR QUANTIFIZIEREN WIE NATÜRLICH BILD NACH VERSCHLEIERUNG
#DAMIT MEINEN WIR INTEGRITÄT IN BEZUG AUF TECHNISCHE NUTZBARKEIT
#IMPACT AUF gesicht, körper, global
#hier gehts weiter usw.
#TODO ODER EINFACH Alles nehmen einfach: Hat Mensch, Face und andere Objekte
#Detektion Gesichter + Body + Min. 1 anderes Objekt haben
#Alle 3 Modelle müssen gut funktionieren
##Metrics for analysis##
#Impact on facial attributes:
#Detection #TODO: Face detection model
#Bounding box (Any/best overlapping box?) FaceDetectionAccuracy = 0.0 - 1.0
#If face bounding box detected
#Bounding box deviation (IoU) FaceBoundingBoxSimilarity = 0.0-1.0
#Facial keypoints #TODO: Facial keypoint, MediaPipe
#Detected? (Visibility score delta) FacialKeypointVisibilitySimilarity = 0.0-1.0
#Deviation? (Coordinate deviation) FacialKeypointCoordinateSimilarity = 0.0-1.0
#Emotion #TODO: Emotion recognition model
#Detected? (Same top1 emotion?) EmotionRecognitionAccuracy = 0.0-1.0
#Vector? (Euclidean distance) EmotionVectorSimilarity = 0.0-1.0
#Face Matching #TODO: Face recognition model
#Same person? (Binary) AnonymizationSuccess = 0.0-1.0
#Embeddings similarity? (Cosine similarity, or other distance) FaceEmbeddingDeviation = 0.0-1.0
#Impact on naturalness of whole person:
#Detection #TODO: YOLOv12
#Bounding box
#Detected? (Any/best overlapping box?) BodyDetectionAccuracy = 0.0-1.0
#If body bounding box detected
#Bounding box deviation? (IoU) BodyBoundingBoxSimilarity = 0.0-1.0
#Segment #TODO: YOLOv12
#Detected? (Any/best overlapping segment?) BodySegmentDetectionAccuracy = 0.0-1.0
#Deviation? (IoU) BodySegmentSimilarity = 0.0-1.0
#Keypoint #TODO: MediaPipe (body)
#Detected? (Visibility score delta)
#Deviation? (Coordinate deviation)
#Global impact (all other objects)
#Detection #TODO: YOLOv12
#Bounding box
#Detected? (Any overlapping box?)
#If any object bounding box detected
#Deviation? (IoU)
#Segment
#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
print("Starting obfuscation platform")
#1: Preprocess images and extract metadata
if Config.tasks["preprocessing"]:
data_loader = DatasetLoader(Config.raw_dataset_path)
raw_datasets_dict = data_loader.load_data(verbose=Config.verbose) #This variable contains a dict with the filenames for each dataset
for dataset_name, image_paths in raw_datasets_dict.items():
data_preprocessor = DataPreprocessor(image_paths, Config.max_images_per_dataset)
output_directory = os.path.join(Config.filtered_output_directory, dataset_name)
data_preprocessor.preprocess_images(output_directory, Config.verbose)
#2: Obfuscate filtered datasets
if Config.tasks["obfuscation"]:
obfuscation_engine = ObfuscationEngine(Config.obfuscation_techniques)
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()