From c85107baf4f9aca56787dc0230f4fe4ecd84c3f9 Mon Sep 17 00:00:00 2001 From: "BIJAN_G16\\bijan" Date: Thu, 22 May 2025 11:09:09 +0200 Subject: [PATCH] Adapted "image_accepted" function for filtering of dataset --- project/__pycache__/config.cpython-310.pyc | Bin 1020 -> 1020 bytes .../image_preprocessor.cpython-310.pyc | Bin 2976 -> 3283 bytes project/config.py | 6 ++-- project/image_preprocessor.py | 31 ++++++++++++++++-- project/main.py | 8 +++-- .../__pycache__/comparator.cpython-310.pyc | Bin 11290 -> 11270 bytes project/meta_data/comparator.py | 4 +-- 7 files changed, 38 insertions(+), 11 deletions(-) diff --git a/project/__pycache__/config.cpython-310.pyc b/project/__pycache__/config.cpython-310.pyc index b7f204807293c4cf3e666934cb82665dfa1f77ed..741941f247b6537f0ced8555e11977e35ecdfd9e 100644 GIT binary patch delta 91 zcmeyv{)e46pO=@50SJCQ*UOkPk@q4$X9@&z&0&e+N#UOOHj?=z7sF&vMu*8=jAo2( fn-4JRGO~#QwG@d>{>*e+0Kx?GL4^3^d(3hGtD6_% delta 91 zcmeyv{)e46pO=@50SN56bTej7&mCDco~dqIgocCccei&V0c<*^|+M(QR@k hquJ&IjJk|$qChQ0qLV)}-4=i_!F&)QHu)a28~|uO7b*Y% diff --git a/project/__pycache__/image_preprocessor.cpython-310.pyc b/project/__pycache__/image_preprocessor.cpython-310.pyc index 775f4d057b6aaf0843037cee32ff089f5cde8123..499042c7aa60706fcc4317d8781e40b90bc57bd9 100644 GIT binary patch delta 1097 zcmZXSO;6N77{@!)x83e;gTx?^K!}Q=2VO!@2_hE=M-LK>X=0l0c7X0~cb1t-7TnDq zOuTvO!9*{fOz>ui2?sv{p1k$sMWbKA3qCU~D}mkgKmX_XJ+Vx<5{Rs=axSSdL{@B0P>Dm?4(@I$01vC>6#^a=&2q4luv8_M&& zp4wIGI8a_Fd_+3jP}vw#0(DD)Se0ZNdcn(H%w`5ulXOW^EvNT0+J^>R;&qAj9B&Sq z4M`tMYUK3EfSQu}lA1XU2DBh3YYyU~tnSF_qO9&?_A~hLJE_UZPDEO2@dtv175WXNzv;ktEviPgVrv;3L zS0UpR*liftT_N|9AI0&tC9tVRI$`YS*`myt+Sw`1`~$s8 B0{H*{ delta 784 zcmZWnzi-n(6ux(MVmr2jib83MB7`UsmLMv>76@7B2C6DmVz7iP*S;oBoY>r1G)0M0 zR5rxqk%hG|p)T-eAU5x;`~e_T-X$$U;jH)h-uu3H_ubjw>hCXB6Wgv39AADkx!VoQljEtcNhY&(vozPiEPctP`LK-TsXNnDS zh^mP?rb%P0V5r-~Q8zi@8i9nfL2)8O$XG^rMaJY=c>=f(*?dZXJf|VqCR|6(0oT~| z1Lp1QBqN6ww7FhD$}ObkVB@SXS{*iIqm;KVU@BAudQc-T*Yn?MW7=%RN#Mt#-TW(a z)Iy2b(A84LMKTnwmhALckcmR^5N!^i@%0^Lkc3-la-B9m|IZIznZmGDVQn$>7IRcJ3ld3mdn;PuA#)S`I=PT Ul5i!zX@#pZ-;(>k^P_eB4}I~fIsgCw diff --git a/project/config.py b/project/config.py index 409166e..4e4c6a3 100644 --- a/project/config.py +++ b/project/config.py @@ -17,9 +17,9 @@ class Config: verbose=True - tasks = {"preprocessing": False, # optional if already done - "obfuscation": False, # optional if already done - "post_extract": 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 # mandatory } diff --git a/project/image_preprocessor.py b/project/image_preprocessor.py index 6f03c93..dcfd713 100644 --- a/project/image_preprocessor.py +++ b/project/image_preprocessor.py @@ -17,17 +17,42 @@ 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: 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) == 0: + return False + if person.segment is None or len(person.segment) == 0: + return False + if person.face_bbox is None or len(person.face_bbox) == 0: + return False + if person.body_keypoints is None or len(person.body_keypoints) == 0: + return False + if person.face_keypoints is None or len(person.face_keypoints) == 0: + return False + if person.dominant_emotion is None: + return False + if person.emotion_vector is None or len(person.emotion_vector) == 0: + return False has_object = len(meta.objects) > 0 - faces_ok = all(p.face_bbox for p in meta.persons) - return has_person and has_object and faces_ok + 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) == 0: + return False + if obj.segment is None or len(obj.segment) == 0: + return False + return has_person and has_object def preprocess_images(self, output_directory, verbose=False): extractor = MetaExtractor() random.shuffle(self.image_paths) print("Current output directory: " + output_directory) + #If the output directory does not exist, create it and it's subdirectories if not os.path.exists(output_directory): - os.mkdir(output_directory) + os.makedirs(output_directory) already_done_count = len([f for f in os.listdir(output_directory) if f.endswith(".json")]) print("Already done: " + str(already_done_count) + " images") print("Remaining: " + str(self.max_images_per_dataset - already_done_count) + " images") diff --git a/project/main.py b/project/main.py index 558f9dd..4f71686 100644 --- a/project/main.py +++ b/project/main.py @@ -30,11 +30,10 @@ from obfuscation.obfuscation_engine import ObfuscationEngine #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"]: + print("1. Running data 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(): @@ -44,19 +43,21 @@ def main(): #2: Obfuscate filtered datasets if Config.tasks["obfuscation"]: + print("2. Running 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"]: + print("3. Running post extraction") 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"]: + print("4. Running 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): @@ -75,6 +76,7 @@ def main(): 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=4) + #TODO: 5. Visualize results if __name__ == '__main__': diff --git a/project/meta_data/__pycache__/comparator.cpython-310.pyc b/project/meta_data/__pycache__/comparator.cpython-310.pyc index 78c9fe7b713cd684b4dbece7d1b747842cc969b3..863090ab7d483e7ed656853a6054527ee93b32ba 100644 GIT binary patch delta 841 zcma)(?`u+F6vsW+n+@4@PHkRXD*9q}71r1WQBg!oTu_ZzbK;xL&1=O>w?|#GwAC!L z*)MmBAgk?F(2I(=1bfq~-ZZFQ5Bm>_pg$m}=iJ5iwtL~j_xYZ4p2IoM(^xeoWhKdM z;NPLm-V5?ODJa1;T(cYx1@n+JmJCfpQY=B!@La6G66A%Fp(IoUFmMGWqppnD+2Ozs z(texB!u+O|Ihsfp)G%XNhPy0t?G7*tX0SjTuyJ%r?*Hjf-tJI_Jauq6w{B-+yagK~ zj1r<4={P|x_^-E!X-_)buqVlb@wV{kk#i?U&Wy4y%ALjyYY(LGm-Rd6w@!o^t{qsh zeKE~a!W>5JgOJzi_MZaOv|?8o!~zfCfxsA!$W5qgKjgQ9LLQqZ3=l38fZ!)A5Q>B= z__4czX9Etai;jzg>x3J)uy-B%Wf_Ovlcuff@QwSWxy+++Z(7Yv;2%e~z!veUCt_Nn znhJjM3_ulsdpycrGVT%X6YLy{QQtm`aNQCwsfmmtuw@+bE<;26>Rka7QtBg2`BbRk zXWtRIPDX=j+goBzO{dtu6rcYn+{Q`&Fg(;=`5%ZoOK1d~edAPihoHYjFR2+qo)F_u zg6tXTRl*u>1_n*~whDMKa9F93tB+JAb(3(5BQ8y;sVq|`W>uEUW>^mA_iaE^JEkab z>IF||iOGx8dDf%?{Xuu&ByWYo#@``l;-Za9SGVpd!1}nO^e_vhJ;wLJRqJb#GQmeU jkI9g~UmuMoXzk7<6O1K_EJe|s@oIG3UL0G&_0ZH`PQu15PNgRJTWMm*EYv9gI&Qn%5XIN7 zW{Bfw*Ei1h^$1D4((uJLPRAMcxI1COoOFK|pk(R?asXNUrFNsP$^t85m%Is!<|lba z(6V%3lF&i8NdSVMFh!Uq+`^s4Ou z#GwV)2I;4SZG5M8+A1T;Vo>eY=E$wIUnF&xFwb#W8rEYere7P=Svob!GC17w0oKhn zO#{ak-%u8#*GDpJ9U}p`1-a3{C!Mx&QOl*Lk&&kX3sGriPF~n!+zxEHUXYXtK0*Tf lTm8o?_n>ym`$nS?#v)TJPOE?KQlihjNipQX2k~v|+21*B(`Enw diff --git a/project/meta_data/comparator.py b/project/meta_data/comparator.py index cd65284..0a1f136 100644 --- a/project/meta_data/comparator.py +++ b/project/meta_data/comparator.py @@ -134,7 +134,7 @@ def _compute_body_keypoint_similarity(kps_a, kps_b, bbox_a, bbox_b): return 0.0, [] #Is shape the same? if len(kps_a) != len(kps_b): - raise ValueError(f"Key-point shapes differ: {kps_a.shape} vs {kps_b.shape}") + raise ValueError(f"Key-point shapes differ: {kps_a} vs {kps_b}") #Filter keypoints with (x,y) == (0,0) coordinates, based on Bounding box origin //keypoints were shifted by bbox offset in advance, this causes not found keypoints (0,0) to be exactly at bbox origin _adapt_body_keypoints(kps_a, bbox_a) _adapt_body_keypoints(kps_b, bbox_b) @@ -146,7 +146,7 @@ def _compute_face_keypoint_similarity(kps_a, kps_b, bbox_a, bbox_b): return 0.0, [] #Is shape the same? if len(kps_a) != len(kps_b): - raise ValueError(f"Key-point shapes differ: {kps_a.shape} vs {kps_b.shape}") + raise ValueError(f"Key-point shapes differ: {kps_a} vs {kps_b}") kps_a = _adapt_face_keypoints(kps_a, bbox_a) kps_b = _adapt_face_keypoints(kps_b, bbox_b) person_keypoint_accuracy, point_position_similarities = _compare_keypoints(kps_a, kps_b)