Added configs
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
class Config:
|
||||
raw_dataset_path="datasets/raw/"
|
||||
base_filtered_output_directory="datasets/filtered/"
|
||||
max_images_per_dataset=5000
|
||||
|
||||
seg_model_type="yolo11m-seg.pt"
|
||||
pose_model_type="yolo11m-pose.pt"
|
||||
face_model_type="retinaface"
|
||||
|
||||
#DEBUG
|
||||
debug_show_preprocessing=False
|
||||
@@ -1,3 +0,0 @@
|
||||
raw_input_path=""
|
||||
filtered_path=""
|
||||
images_per_dataset=-1
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 685 KiB |
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,16 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
from config import Config
|
||||
from meta_data_extractor import MetaExtractor, ImageMeta
|
||||
from meta_data_visualizer import visualize_metadata
|
||||
import cv2
|
||||
|
||||
|
||||
|
||||
|
||||
class DataPreprocessor:
|
||||
def __init__(self, image_paths):
|
||||
def __init__(self, image_paths, max_images_per_dataset):
|
||||
self.image_paths = image_paths
|
||||
self.max_images_per_dataset = max_images_per_dataset
|
||||
|
||||
#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:
|
||||
@@ -18,32 +19,38 @@ class DataPreprocessor:
|
||||
faces_ok = all(p.face_bbox for p in meta.persons)
|
||||
return has_person and has_object and faces_ok
|
||||
|
||||
def preprocess_images(self, output_directory, debug=False):
|
||||
def preprocess_images(self, output_directory):
|
||||
extractor = MetaExtractor()
|
||||
if not os.path.exists(output_directory):
|
||||
os.mkdir(output_directory)
|
||||
|
||||
img_counter = 0
|
||||
for img_file_path in self.image_paths:
|
||||
image_meta = extractor.extract(img_file_path)
|
||||
if debug:
|
||||
print("Debug Routine")
|
||||
img = cv2.imread(img_file_path)
|
||||
cv2.imshow("Before", img)
|
||||
cv2.waitKey()
|
||||
img_vis = visualize_metadata(img, image_meta)
|
||||
cv2.imshow("After", img_vis)
|
||||
cv2.waitKey()
|
||||
print("image_meta")
|
||||
print(image_meta.to_dict())
|
||||
exit()
|
||||
if Config.debug_show_preprocessing:
|
||||
self._debug_show(image_meta, img_file_path)
|
||||
|
||||
is_accepted = self._is_accepted(image_meta)
|
||||
if is_accepted:
|
||||
base_name = os.path.basename(img_file_path).split(".")[0]
|
||||
meta_data_file_path = os.path.join(output_directory, os.path.basename(img_file_path).split(".")[0] + ".json")
|
||||
output_image_file_path = os.path.join(output_directory, os.path.basename(img_file_path))
|
||||
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)
|
||||
img_counter += 1
|
||||
if img_counter >= self.max_images_per_dataset:
|
||||
return
|
||||
|
||||
print(base_name)
|
||||
exit()
|
||||
|
||||
with open(os.path.join(output_directory, f"{base_name}.json"), "w") as f:
|
||||
json.dump(meta, f, indent=2)
|
||||
def _debug_show(self, image_meta, img_file_path):
|
||||
print("Debug Routine")
|
||||
img = cv2.imread(img_file_path)
|
||||
cv2.imshow("Before", img)
|
||||
cv2.waitKey()
|
||||
img_vis = visualize_metadata(img, image_meta)
|
||||
cv2.imshow("After", img_vis)
|
||||
cv2.waitKey()
|
||||
print("image_meta")
|
||||
print(image_meta.to_dict())
|
||||
exit()
|
||||
|
||||
|
||||
+7
-25
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from config import Config
|
||||
from data_loader import DatasetLoader
|
||||
from image_preprocessor import DataPreprocessor
|
||||
|
||||
@@ -89,39 +90,20 @@ from image_preprocessor import DataPreprocessor
|
||||
def main():
|
||||
print("Starting obfuscation platform")
|
||||
#First: load the image datasets
|
||||
raw_dataset_path = "datasets/raw/"
|
||||
data_loader = DatasetLoader(raw_dataset_path)
|
||||
data_loader = DatasetLoader(Config.raw_dataset_path)
|
||||
raw_datasets_dict = data_loader.load_data() #This variable contains a dict with the filenames for each dataset
|
||||
#Second: filter the image data and extract meta data
|
||||
base_output_directory = "datasets/filtered/"
|
||||
for dataset_name, image_paths in raw_datasets_dict.items():
|
||||
data_preprocessor = DataPreprocessor(image_paths)
|
||||
output_directory = os.path.join(base_output_directory, dataset_name)
|
||||
data_preprocessor = DataPreprocessor(image_paths, Config.max_images_per_dataset)
|
||||
output_directory = os.path.join(Config.base_filtered_output_directory, dataset_name)
|
||||
data_preprocessor.preprocess_images(output_directory)
|
||||
|
||||
|
||||
#TODO: Datenset filtern und Bilder mit Metadaten speichern. Für jedes Bild gilt:
|
||||
#1. Hat Bild Bobx mit min. 1 anderes Objekt als Mensch?
|
||||
#1.1 Gibt es zu Bbox Segment?
|
||||
#2. Hat Bild Bbox mit Mensch?
|
||||
#2.1 Hat Mensch Segment?
|
||||
#2.2 Extrahiere Keypoints
|
||||
#3. Hat Mensch Bbox Gesicht Bbox?
|
||||
#3.3 Hat
|
||||
# USW
|
||||
#TODO: Obfuscation analysis process //For each obfuscation method
|
||||
#TODO: Output folder (true/false)
|
||||
#TODO: Run analysis of "after" images
|
||||
|
||||
|
||||
|
||||
# Based on that i want to extract meta data:
|
||||
# -The bounding and segment of the other objects (with yolo11-seg)
|
||||
# -The segment and boundingbox of the persons (with yolo11-seg)
|
||||
# -The body keypoints of the persons
|
||||
# -The Face bounding box of the persons (idk which model, please recommend one)
|
||||
# -The Face keypoints of the persons (with mediapipe)
|
||||
# -The emotion of the person
|
||||
|
||||
#TODO: filter data by criteria; Like N-Images
|
||||
|
||||
#configure pipeline
|
||||
#load data
|
||||
#pre-process data //create dataset based on specific criteria
|
||||
|
||||
@@ -10,6 +10,9 @@ from ultralytics import YOLO
|
||||
from deepface import DeepFace
|
||||
import mediapipe as mp
|
||||
|
||||
from config import Config
|
||||
|
||||
|
||||
@dataclass
|
||||
class ObjectMeta:
|
||||
label: str
|
||||
@@ -53,15 +56,12 @@ def _deepface_bbox_to_xyxy(face_dict: Dict[str, Any]) -> List[int]:
|
||||
|
||||
|
||||
class MetaExtractor:
|
||||
def __init__(self,
|
||||
seg_weights: str = "yolo11m-seg.pt",
|
||||
pose_weights: str = "yolo11m-pose.pt",
|
||||
face_backend: str = "retinaface"):
|
||||
self.segmentor = YOLO(seg_weights)
|
||||
self.pose_estimator = YOLO(pose_weights)
|
||||
def __init__(self):
|
||||
self.segmentor = YOLO(Config.seg_model_type)
|
||||
self.pose_estimator = YOLO(Config.pose_model_type)
|
||||
|
||||
# DeepFace will lazy-load the detector the first time we call it.
|
||||
self._face_backend = face_backend
|
||||
self._face_backend = Config.face_model_type
|
||||
|
||||
# MediaPipe
|
||||
self._mp_mesh = mp.solutions.face_mesh.FaceMesh(static_image_mode=True, refine_landmarks=True, max_num_faces=1)
|
||||
|
||||
Reference in New Issue
Block a user