Files
obfuscation_platform/project/main.py
T

84 lines
4.8 KiB
Python

import json
import os
from config import Config
from data_loader import DatasetLoader
from image_preprocessor import DataPreprocessor
from meta_data.comparator import Comparator
from meta_data.post_extraction import PostExtractor
from obfuscation.obfuscation_engine import ObfuscationEngine
##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.
def main():
#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
if Config.tasks["post_extract"]:
post_extractor = PostExtractor(Config.obfuscated_output_directory)
post_extractor.extract()
#4: Analyze impact of obfuscation
#For each before folder, compare with after folder (after each technique)
if Config.tasks["analysis"]:
comparator = Comparator()
print("Starting to analyze impact of obfuscation")
for before_dataset_name in os.listdir(Config.filtered_output_directory):
before_dataset_path = os.path.join(Config.filtered_output_directory, before_dataset_name)
for after_dataset_name in os.listdir(Config.obfuscated_output_directory):
if before_dataset_name == after_dataset_name:
after_dataset_path = os.path.join(Config.obfuscated_output_directory, after_dataset_name)
#For each technique, compare the datasets
for technique_name in os.listdir(after_dataset_path):
if (technique_name == "aaa") and (before_dataset_name == "celeba"): #TODO ENTFERNEN!!!
#if (technique_name == "aaa") and (before_dataset_name == "zzz"): #TODO ENTFERNEN!!!
#TODO aber auch die datensets die dazukamen filtern usw... also in den ordnern
technique_path = os.path.join(after_dataset_path, technique_name)
print(f"Comparing {before_dataset_name} with {technique_name} obfuscation")
technique_result_dict = comparator.compare_with_before_and_after_folder(before_dataset_path, technique_path)
#Save results in evaluation_results_directory as json
current_technique_results_directory = os.path.join(Config.evaluation_results_directory, f"results_{before_dataset_name}_{technique_name}.json")
print(f"Saving results in {current_technique_results_directory}")
with open(current_technique_results_directory, "w") as f:
json.dump(technique_result_dict, f, indent=3)
if __name__ == '__main__':
main()