Added code for metadata extraction of obfuscated images
This commit is contained in:
Binary file not shown.
@@ -17,6 +17,7 @@ class Config:
|
||||
|
||||
tasks = {"preprocessing": True, # optional if already done
|
||||
"obfuscation": True, # optional if already done
|
||||
"post_extract": True, # optional if already done
|
||||
"analysis": True # mandatory
|
||||
}
|
||||
|
||||
|
||||
+28
-45
@@ -1,7 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
from config import Config
|
||||
from data_loader import DatasetLoader
|
||||
from image_preprocessor import DataPreprocessor
|
||||
from meta_data.meta_data_extractor import MetaExtractor
|
||||
from meta_data.post_extraction import PostExtractor
|
||||
from obfuscation.obfuscation_engine import ObfuscationEngine
|
||||
|
||||
|
||||
@@ -48,46 +51,8 @@ from obfuscation.obfuscation_engine import ObfuscationEngine
|
||||
#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)
|
||||
#TODO: Zusätzliche analysen für Journal: Konfidenz, Mehrere Modelle für Gesichtserkennung, Andere Datensets (in the wild, zb. MSCOCO)
|
||||
def main():
|
||||
#TODO: die analysen vorher/nachher
|
||||
#TODO: gute techniken hinzufügen
|
||||
@@ -108,12 +73,30 @@ 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 Config.tasks["post_extract"]:
|
||||
post_extractor = PostExtractor(Config.obfuscated_output_directory)
|
||||
post_extractor.extract()
|
||||
|
||||
#4: Analyze impact of obfuscation
|
||||
#TODO: Compare before and after metadata for each dataset, for each technique;
|
||||
#TODO: ES FEHLT NOCH EIN MODEL FÜR GESICHTER MATCHING; WIe gut ist verschleierung eigentlich?
|
||||
#TODO: Generate some "evaluation_output" for dataset and technique
|
||||
|
||||
#Für jedes Datenset, für jede Technik messen, welchen einfluss die anonymisierung hat
|
||||
#Person
|
||||
#Person Accuracy: Wird Person gefunden? Bbox IoU > 0.5
|
||||
#Person Segment Similarity: Wie ähnlich sind die Segmentierungen? Polygon Similarity
|
||||
|
||||
#Face Accuracy: Wird Gesicht gefunden? Bbox IoU > 0.5
|
||||
#Obfuscation Success: Wurde Person nicht wiedererkannt? Face Matching
|
||||
#Face Mesh Similarity: Wie ähnlich sind die Meshpunkte? Facial Keypoints Similarity
|
||||
#Face Emotion Accuracy: Wird Emotion erkannt? Top1 Emotion Matching
|
||||
#Face Emotion Vector Similarity: Wie ähnlich sind die Emotionen? Vector Similarity
|
||||
|
||||
#Global (Für jedes weitere Objekt im Ursprungsbild)
|
||||
#Object Accuracy: Wird das Objekt erkannt? Bbox IoU > 0.5
|
||||
#Object Segment Similarity: Wie ähnlich sind die Segmentierungen? Polygon Similarity
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from meta_data.meta_data_extractor import MetaExtractor
|
||||
from tqdm import tqdm
|
||||
from config import Config
|
||||
|
||||
|
||||
class PostExtractor:
|
||||
def __init__(self, directory):
|
||||
self.directory = directory
|
||||
|
||||
def extract(self):
|
||||
#Extract metadata for each obfuscated technique
|
||||
meta_extractor = MetaExtractor()
|
||||
for dataset_name in tqdm(os.listdir(self.directory), desc="Extracting metadata for datasets"): # For each dataset
|
||||
obfuscated_directory = os.path.join(self.directory, dataset_name)
|
||||
for technique_name in os.listdir(obfuscated_directory): # For each technique
|
||||
technique_directory = os.path.join(obfuscated_directory, technique_name)
|
||||
for img_file_path in os.listdir(technique_directory): # For each image
|
||||
meta_file_name = os.path.join(Config.obfuscated_output_directory, dataset_name, technique_name, img_file_path.split(".")[0] + ".json")
|
||||
if os.path.exists(meta_file_name):
|
||||
print("Skipping", meta_file_name, "as it already exists")
|
||||
continue
|
||||
image_meta = meta_extractor.extract(os.path.join(technique_directory, img_file_path))
|
||||
with open(meta_file_name, "w") as f:
|
||||
json.dump(image_meta.to_dict(), f, indent=2)
|
||||
Reference in New Issue
Block a user