Adapted copy logic of images.
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 362 KiB |
|
After Width: | Height: | Size: 145 KiB |
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 2.2 MiB |
@@ -28,10 +28,10 @@ class Config:
|
||||
|
||||
verbose=True
|
||||
|
||||
tasks = {"preprocessing": False, # optional if already done
|
||||
"obfuscation": False, # optional if already done
|
||||
"post_extract": False, # optional if already done
|
||||
"analysis": False, # optional if already done
|
||||
tasks = {"preprocessing": True, # optional if already done
|
||||
"obfuscation": True, # optional if already done
|
||||
"post_extract": True, # optional if already done
|
||||
"analysis": True, # optional if already done
|
||||
"visualize": True #Should be always true, since it is the last step for reasoning
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ class Config:
|
||||
debug_show_preprocessing=False
|
||||
|
||||
obfuscation_techniques=[
|
||||
Synthetic(),
|
||||
Style(),
|
||||
Swap(),
|
||||
#Synthetic(),
|
||||
#Style(),
|
||||
#Swap(),
|
||||
Blackening(),
|
||||
Randoming(),
|
||||
Blurring(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
|
||||
from config import Config
|
||||
from meta_data.meta_data_extractor import MetaExtractor, ImageMeta
|
||||
@@ -15,16 +16,19 @@ class DataPreprocessor:
|
||||
|
||||
#This method filters the images by specific criteria and extracts and saves the metadata for each filtered image
|
||||
def _is_accepted(self, meta: ImageMeta) -> bool:
|
||||
#Image has at least 1 person (BBox)
|
||||
#Each person needs to have detected face
|
||||
#At least 1 object
|
||||
has_person = len(meta.persons) > 0
|
||||
#Check whether all fields in each person is valid
|
||||
for person in meta.persons:
|
||||
if person.label is None or person.label != "person":
|
||||
return False
|
||||
if person.bbox is None or len(person.bbox) < 4:
|
||||
if person.bbox is None or len(person.bbox) != 4:
|
||||
return False
|
||||
if person.segment is None or len(person.segment) < 3:
|
||||
return False
|
||||
if person.face_bbox is None or len(person.face_bbox) < 4:
|
||||
if person.face_bbox is None or len(person.face_bbox) != 4:
|
||||
return False
|
||||
if person.body_keypoints is None or len(person.body_keypoints) == 0:
|
||||
return False
|
||||
@@ -38,7 +42,7 @@ class DataPreprocessor:
|
||||
for obj in meta.objects:
|
||||
if obj.label is None or obj.label == "" or obj.label == "person":
|
||||
return False
|
||||
if obj.bbox is None or len(obj.bbox) < 4:
|
||||
if obj.bbox is None or len(obj.bbox) != 4:
|
||||
return False
|
||||
if obj.segment is None or len(obj.segment) < 3:
|
||||
return False
|
||||
@@ -77,8 +81,7 @@ class DataPreprocessor:
|
||||
continue
|
||||
with open(meta_data_file_path, "w") as f:
|
||||
json.dump(image_meta.to_dict(), f, indent=2)
|
||||
img = cv2.imread(img_file_path)
|
||||
cv2.imwrite(output_image_file_path, img)
|
||||
shutil.copy2(img_file_path, output_image_file_path)
|
||||
img_counter += 1
|
||||
|
||||
def _debug_show(self, image_meta, img_file_path):
|
||||
@@ -87,8 +90,12 @@ class DataPreprocessor:
|
||||
cv2.imshow("Before", img)
|
||||
cv2.waitKey()
|
||||
img_vis = visualize_metadata(img, image_meta)
|
||||
cv2.imshow("After", img_vis)
|
||||
winname = "Test"
|
||||
cv2.namedWindow(winname) # Create a named window
|
||||
cv2.moveWindow(winname, 40,30) # Move it to (40,30)
|
||||
cv2.imshow(winname, img_vis)
|
||||
cv2.waitKey()
|
||||
cv2.destroyAllWindows()
|
||||
print("image_meta")
|
||||
print(image_meta.to_dict())
|
||||
exit()
|
||||
|
||||
@@ -10,11 +10,11 @@ from meta_data.post_extraction import PostExtractor
|
||||
from obfuscation.obfuscation_engine import ObfuscationEngine
|
||||
from visualization.visualizer import Visualizer
|
||||
|
||||
# import random
|
||||
# import torch
|
||||
#
|
||||
# random.seed(Config.seed)
|
||||
# torch.manual_seed(Config.seed)
|
||||
import random
|
||||
import torch
|
||||
|
||||
random.seed(Config.seed)
|
||||
torch.manual_seed(Config.seed)
|
||||
|
||||
def main():
|
||||
print("Starting obfuscation platform")
|
||||
@@ -24,9 +24,10 @@ def main():
|
||||
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():
|
||||
random.shuffle(image_paths)
|
||||
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) #TODO HIER DAS PRÜFEN
|
||||
data_preprocessor.preprocess_images(output_directory, Config.verbose)
|
||||
|
||||
#2: Obfuscate filtered datasets
|
||||
if Config.tasks["obfuscation"]:
|
||||
@@ -38,7 +39,7 @@ def main():
|
||||
if Config.tasks["post_extract"]:
|
||||
print("3. Running post extraction")
|
||||
post_extractor = PostExtractor(Config.obfuscated_output_directory)
|
||||
post_extractor.extract() #TODO HIER DAS PRÜFEN
|
||||
post_extractor.extract()
|
||||
|
||||
#4: Analyze impact of obfuscation
|
||||
#For each before folder, compare with after folder (after each technique)
|
||||
@@ -66,7 +67,7 @@ def main():
|
||||
|
||||
if Config.tasks["visualize"]:
|
||||
print("5. Running visualization")
|
||||
out_dir = Path(Config.visual_results_directory);
|
||||
out_dir = Path(Config.visual_results_directory)
|
||||
out_dir.mkdir(exist_ok=True)
|
||||
viz = Visualizer(Config.evaluation_results_directory)
|
||||
for ds in viz.datasets():
|
||||
@@ -81,8 +82,6 @@ def main():
|
||||
print(f"📊 {save_path} gespeichert")
|
||||
|
||||
|
||||
#TODO: im comparator die Namen anpassen
|
||||
|
||||
#TODO: Die Berechnung jeder einzelnen Metrik überprüfen, metriken prüfen?
|
||||
#TODO: Die Validitätsprüfung der Daten überprüfen
|
||||
#TODO: WIE WERDEN DIE METRIKEN BERECHNET?
|
||||
|
||||
@@ -102,7 +102,6 @@ class MetaExtractor:
|
||||
|
||||
person_ids = np.where(classes == 0)[0] # COCO class 0 == person
|
||||
other_ids = np.where(classes != 0)[0]
|
||||
|
||||
# ----------- PER-PERSON METADATA -----------------------------------
|
||||
persons: list[PersonMeta] = []
|
||||
for idx in person_ids:
|
||||
|
||||
@@ -43,11 +43,11 @@ class Visualizer:
|
||||
# ---- Styling options ------------------------------------------
|
||||
font_sizes: dict | None = None, # {'axes':12,'ticks':10,'legend':10,'barlabel':8,'title':13}
|
||||
hatch_cycle: tuple[str, ...] = ("///", "..", "**", "++", "..", "oo", "**"),
|
||||
bar_alpha: float = 0.9,
|
||||
bar_alpha: float = 1,
|
||||
annotate: bool = True,
|
||||
annotate_fmt: str = "{v:.1f}", # no % sign as requested
|
||||
barlabel_padding: int = 2,
|
||||
top_padding: float = 0.06, # 6% headroom
|
||||
top_padding: float = 0.01, # 6% headroom
|
||||
legend_ncols: int | None = None,
|
||||
percent_axis: bool = True, # keep % on the y-axis ticks
|
||||
):
|
||||
@@ -73,7 +73,7 @@ class Visualizer:
|
||||
pivot.plot(kind="bar", ax=ax, edgecolor="black", linewidth=0.6)
|
||||
|
||||
# ---------------- Font sizes ------------------------------------
|
||||
fs = dict(title=13, axes=12, ticks=12, legend=12, barlabel=6)
|
||||
fs = dict(title=13, axes=13, ticks=13, legend=11, barlabel=6.3)
|
||||
if font_sizes:
|
||||
fs.update(font_sizes)
|
||||
|
||||
|
||||