rest of the last commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+25605
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
+5
-1
@@ -1,3 +1,7 @@
|
||||
datasets/*
|
||||
evaluation_results/*
|
||||
visual_results/*
|
||||
visual_results/*
|
||||
__pycache__/*
|
||||
project/__pycache__/*
|
||||
project/obfuscation/__pycache__/*
|
||||
models/*
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3
-3
@@ -3,7 +3,7 @@ from obfuscation.block_random import Randoming
|
||||
from obfuscation.block_white import Whitening
|
||||
from obfuscation.blurring import Blurring
|
||||
from obfuscation.pixelation import Pixelation
|
||||
|
||||
from obfuscation.ugatit import U_GAT_IT
|
||||
|
||||
class Config:
|
||||
raw_dataset_path="datasets/raw/"
|
||||
@@ -32,9 +32,9 @@ class Config:
|
||||
debug_show_preprocessing=False
|
||||
|
||||
obfuscation_techniques=[
|
||||
U_GAT_IT(),
|
||||
Blackening(),
|
||||
#Whitening(),
|
||||
#Randoming(),
|
||||
Randoming(),
|
||||
Blurring(),
|
||||
Pixelation()
|
||||
]
|
||||
+10
-31
@@ -10,27 +10,13 @@ from meta_data.post_extraction import PostExtractor
|
||||
from obfuscation.obfuscation_engine import ObfuscationEngine
|
||||
from visualization.visualizer import Visualizer
|
||||
|
||||
import random
|
||||
import torch
|
||||
|
||||
##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
|
||||
EXPERIMENT_SEED = 42
|
||||
random.seed(EXPERIMENT_SEED)
|
||||
torch.manual_seed(EXPERIMENT_SEED)
|
||||
|
||||
#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():
|
||||
print("Starting obfuscation platform")
|
||||
@@ -95,23 +81,16 @@ def main():
|
||||
save=save_path)
|
||||
print(f"📊 {save_path} gespeichert")
|
||||
|
||||
#TODO: METRIKEN --> Nochmal für alle übrig gebliebenen scores, to berechnung überprüfen!
|
||||
|
||||
#TODO: Unnötige Verschleierungen entfernen
|
||||
#TODO: Techniken hinzufügen
|
||||
#TODO: Bars nach Oberkategorie gruppieren?
|
||||
#TODO: Möglicherweise Metriken anpassen
|
||||
|
||||
#TODO: Verteilung von Gesichtern und Objekten Visualisieren mit Heatmap
|
||||
|
||||
#TODO: Visualisierungen
|
||||
#TODO: Skala bei visualisierung immer 0 - 100, nicht dynamisch anpassen
|
||||
#TODO: Legende anpassen: 1. "metric" streichen 2. die bezeichner der Kategorien anpassen
|
||||
#TODO: Namen der Techniken anpassen
|
||||
#TODO: Zahlen mit % ergänzen
|
||||
#TODO: Überschrift oben entfernen
|
||||
#TODO: X und Y Achsen überschrift anpassen
|
||||
|
||||
#TODO: Nochmal alles laufen lassen, wenn neue Techniken gefunden wurden
|
||||
|
||||
#TODO: Wenn zu wenig platz im Paper dann ohne utk
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -251,26 +251,26 @@ def write_image_results_to_folder_result_dict(image_result_dict, folder_result_d
|
||||
def compute_scores(folder_result_dict):
|
||||
scores = {
|
||||
"person": {
|
||||
"person_found_accuracy": (folder_result_dict["found_matching_persons_count"] / folder_result_dict["before_person_count"]) * 100.0,
|
||||
"\mathrm{Acc}_\mathrm{det}": (folder_result_dict["found_matching_persons_count"] / folder_result_dict["before_person_count"]) * 100.0,
|
||||
#"person_bbox_iou_avg": np.mean(folder_result_dict["person_bbox_ious"]) if len(folder_result_dict["person_bbox_ious"]) > 0 else 0.0,
|
||||
"person_segment_iou_avg": np.mean(folder_result_dict["person_segment_ious"]) if len(folder_result_dict["person_segment_ious"]) > 0 else 0.0,
|
||||
"\mathrm{mIoU}_\mathrm{seg}": np.mean(folder_result_dict["person_segment_ious"]) if len(folder_result_dict["person_segment_ious"]) > 0 else 0.0,
|
||||
#"person_keypoint_accuracy_avg": np.mean(folder_result_dict["person_keypoint_accuracies"]) if len(folder_result_dict["person_keypoint_accuracies"]) > 0 else 0.0,
|
||||
"person_keypoint_position_similarity_avg": np.mean(folder_result_dict["person_keypoint_position_similarities"]) if len(folder_result_dict["person_keypoint_position_similarities"]) > 0 else 0.0,
|
||||
"\mathrm{Sim}_\mathrm{kp}": np.mean(folder_result_dict["person_keypoint_position_similarities"]) if len(folder_result_dict["person_keypoint_position_similarities"]) > 0 else 0.0,
|
||||
},
|
||||
"face": {
|
||||
"face_found_accuracy": (folder_result_dict["found_face_count"] / folder_result_dict["before_person_count"]) * 100.0,
|
||||
"\mathrm{Acc}_\mathrm{det}": (folder_result_dict["found_face_count"] / folder_result_dict["before_person_count"]) * 100.0,
|
||||
#"face_bbox_iou_avg": np.mean(folder_result_dict["face_bbox_ious"]) if len(folder_result_dict["face_bbox_ious"]) > 0 else 0.0,
|
||||
"top1_emotion_accuracy": (folder_result_dict["same_emotion_count"] / folder_result_dict["found_face_count"]) * 100.0 if folder_result_dict["found_face_count"] > 0 else 0.0,
|
||||
"\mathrm{Acc}_\mathrm{emo}": (folder_result_dict["same_emotion_count"] / folder_result_dict["found_face_count"]) * 100.0 if folder_result_dict["found_face_count"] > 0 else 0.0,
|
||||
#"emotion_vector_similarity_avg": np.mean(folder_result_dict["emotion_vector_similarities"]) if len(folder_result_dict["emotion_vector_similarities"]) > 0 else 0.0,
|
||||
"obfuscation_accuracy": (1.0 - (folder_result_dict["same_person_counter"] / folder_result_dict["found_face_count"])) * 100.0 if folder_result_dict["found_face_count"] > 0 else 100.0,
|
||||
"\mathrm{Acc}_\mathrm{deID}": (1.0 - (folder_result_dict["same_person_counter"] / folder_result_dict["found_face_count"])) * 100.0 if folder_result_dict["found_face_count"] > 0 else 100.0,
|
||||
#"identity_distance_avg": np.mean(folder_result_dict["identity_distances"]) if len(folder_result_dict["identity_distances"]) > 0 else 100.0,
|
||||
#"face_keypoint_position_similarity_avg": np.mean(folder_result_dict["face_keypoint_position_similarities"]) if len(folder_result_dict["face_keypoint_position_similarities"]) > 0 else 0.0
|
||||
},
|
||||
"object": {
|
||||
"object_found_accuracy": (folder_result_dict["found_matching_objects_count"] / folder_result_dict["before_object_count"]) * 100.0,
|
||||
"\mathrm{Acc}_\mathrm{det}": (folder_result_dict["found_matching_objects_count"] / folder_result_dict["before_object_count"]) * 100.0,
|
||||
#"object_bbox_iou_avg": np.mean(folder_result_dict["object_bbox_ious"]) if len(folder_result_dict["object_bbox_ious"]) > 0 else 0.0,
|
||||
"object_segment_iou_avg": np.mean(folder_result_dict["object_segment_ious"]) if len(folder_result_dict["object_segment_ious"]) > 0 else 0.0,
|
||||
"object_class_accuracy": (folder_result_dict["found_matching_classes_count"] / folder_result_dict["before_object_count"]) * 100.0
|
||||
"\mathrm{mIoU}_\mathrm{seg}": np.mean(folder_result_dict["object_segment_ious"]) if len(folder_result_dict["object_segment_ious"]) > 0 else 0.0,
|
||||
"\mathrm{Acc}_\mathrm{cls}": (folder_result_dict["found_matching_classes_count"] / folder_result_dict["before_object_count"]) * 100.0
|
||||
},
|
||||
"meta": {
|
||||
"person": {
|
||||
@@ -387,13 +387,11 @@ class Comparator:
|
||||
same_person_counter += 1
|
||||
identity_distances.append(identity_distance)
|
||||
|
||||
_, point_position_similarities = _compute_face_keypoint_similarity(before_person["face_keypoints"], after_person["face_keypoints"], before_person["face_bbox"], after_person["face_bbox"])
|
||||
face_keypoint_position_similarities.extend(point_position_similarities)
|
||||
_, face_point_position_similarities = _compute_face_keypoint_similarity(before_person["face_keypoints"], after_person["face_keypoints"], before_person["face_bbox"], after_person["face_bbox"])
|
||||
face_keypoint_position_similarities.extend(face_point_position_similarities)
|
||||
|
||||
|
||||
for before_object in before_meta["objects"]:
|
||||
#TODO: Problem, wenn objekt nicht gefunden wird
|
||||
#TODO: ValueError: A linearring requires at least 4 coordinates.
|
||||
result = _find_best_matching_object(before_object, after_meta["objects"])
|
||||
if result is None:
|
||||
continue
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -17,4 +17,4 @@ class Blackening(ObfuscationTechnique):
|
||||
return obf
|
||||
|
||||
def name(self):
|
||||
return "blackening"
|
||||
return "Black"
|
||||
@@ -17,4 +17,4 @@ class Randoming(ObfuscationTechnique):
|
||||
return obf
|
||||
|
||||
def name(self):
|
||||
return "random"
|
||||
return "Random"
|
||||
@@ -13,4 +13,4 @@ class Blurring(ObfuscationTechnique):
|
||||
return cv2.GaussianBlur(face_roi_img_bgr, ksize=(self.kernel, self.kernel), sigmaX=0, sigmaY=0)
|
||||
|
||||
def name(self):
|
||||
return "blurring"
|
||||
return "Blur"
|
||||
@@ -23,4 +23,4 @@ class Pixelation(ObfuscationTechnique):
|
||||
return cv2.resize(tmp, (w, h), interpolation=cv2.INTER_NEAREST)
|
||||
|
||||
def name(self):
|
||||
return "pixelation"
|
||||
return "Pixel"
|
||||
@@ -0,0 +1,71 @@
|
||||
import os, sys, cv2, torch, numpy as np
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
from models.VToonify.model.vtoonify import VToonify
|
||||
from utils.align_face import align_face # helper to crop & align
|
||||
from utils.face_parsing import init_parsing # segmentation net
|
||||
|
||||
from your_module.base import ObfuscationTechnique # adjust import path
|
||||
|
||||
|
||||
class VToonifyTechnique(ObfuscationTechnique):
|
||||
"""
|
||||
Single-image face stylisation via VToonify (caricature/anime/…).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ckpt_path : str | Path
|
||||
Path to a *.pth* checkpoint (e.g. vtoonify_plus_cartoon.pth).
|
||||
style : str
|
||||
One of ["cartoon", "anime", "ink", ...] – only used to name() the technique.
|
||||
device : 'cuda' | 'cpu'
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
ckpt_path: str | Path = "models/VToonify/checkpoints/vtoonify_plus_cartoon.pth",
|
||||
style: str = "cartoon",
|
||||
device: str = "cuda"):
|
||||
self.device = torch.device(device if torch.cuda.is_available() else "cpu")
|
||||
self.style = style
|
||||
|
||||
# ❶ build generator, load weights -----------------------------------
|
||||
self.net = VToonify(backbone='DualStyleGAN').to(self.device)
|
||||
ckpt = torch.load(ckpt_path, map_location="cpu")
|
||||
self.net.load_state_dict(ckpt['g_ema'], strict=False)
|
||||
self.net.eval()
|
||||
|
||||
# ❷ face-alignment & parsing nets -----------------------------------
|
||||
self.fa = align_face.FaceAligner(device=self.device) # dlib-based
|
||||
self.parser = init_parsing(device=self.device) # BiSeNet-R18
|
||||
|
||||
# ---------- helper -------------------------------------------------------
|
||||
def _stylise(self, aligned_rgb: np.ndarray, lm: np.ndarray) -> np.ndarray:
|
||||
"""
|
||||
aligned_rgb – 224×224 RGB float32 [0,1]
|
||||
returns stylised aligned RGB uint8
|
||||
"""
|
||||
x = torch.from_numpy(aligned_rgb).permute(2,0,1).unsqueeze(0) # 1×3×224×224
|
||||
x = x.to(self.device) * 2 - 1 # [0,1]→[-1,1]
|
||||
|
||||
with torch.no_grad():
|
||||
seg = self.parser(x, False) # hair/skin mask
|
||||
out = self.net(x, seg=seg, latent=None, inject_index=4) # generator
|
||||
out = (out.clamp(-1,1).add(1).mul(127.5)).cpu().numpy()
|
||||
out = out[0].transpose(1,2,0).astype(np.uint8) # RGB
|
||||
return align_face.reverse_align(out, lm) # un-warp
|
||||
|
||||
# ---------- API for your framework --------------------------------------
|
||||
def obfuscate(self, face_roi_img_bgr: np.ndarray) -> np.ndarray:
|
||||
# 1) align
|
||||
aligned_rgb, lm = self.fa.align_and_crop(face_roi_img_bgr[..., ::-1])
|
||||
# 2) stylise
|
||||
stylised_rgb = self._stylise(aligned_rgb, lm)
|
||||
# 3) resize back to ROI
|
||||
stylised_bgr = cv2.cvtColor(stylised_rgb, cv2.COLOR_RGB2BGR)
|
||||
return cv2.resize(stylised_bgr,
|
||||
(face_roi_img_bgr.shape[1], face_roi_img_bgr.shape[0]),
|
||||
interpolation=cv2.INTER_LINEAR)
|
||||
|
||||
def name(self) -> str:
|
||||
return f"VToonify_{self.style}"
|
||||
|
||||
Binary file not shown.
@@ -49,15 +49,23 @@ class Visualizer:
|
||||
|
||||
# Pivot: index = technique, columns = metrics
|
||||
pivot = sub.pivot(index="technique", columns="metric", values="value")
|
||||
# Interpret the metric name as latex code for maths
|
||||
pivot.columns = [f"${c}$" for c in pivot.columns]
|
||||
|
||||
print(pivot)
|
||||
fig, ax = plt.subplots(figsize=figsize)
|
||||
pivot.plot(kind="bar", ax=ax)
|
||||
ax.set_xlabel("") # X axis should have no title
|
||||
ax.tick_params(axis='x', rotation=0) # X axis should have no title
|
||||
|
||||
|
||||
|
||||
ax.set_ylim(0, 100)
|
||||
ax.set_yticklabels([f"{y}%" for y in ax.get_yticks()])
|
||||
|
||||
ax.set_title(f"{dataset} – {category.capitalize()} metrics")
|
||||
ax.set_xlabel("Technique")
|
||||
ax.set_ylabel("score")
|
||||
ax.grid(axis="y", linestyle="--", alpha=0.4)
|
||||
ax.legend(title="metric", bbox_to_anchor=(1.02, 1), loc="upper left")
|
||||
ax.legend(loc="lower left") #best
|
||||
# ax.legend(bbox_to_anchor=(1.02, 1), loc="lower left") #best
|
||||
|
||||
plt.tight_layout()
|
||||
if save:
|
||||
@@ -65,6 +73,8 @@ class Visualizer:
|
||||
plt.close(fig)
|
||||
return fig, ax
|
||||
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# intern
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user