import os import json import re import matplotlib.pyplot as plt from collections import defaultdict # Ordner mit JSON-Dateien input_dir = "./json_results" # Regex um dataset und technik aus Dateinamen zu extrahieren filename_pattern = re.compile(r"results_(.+?)_(.+?)\.json") # Datenstruktur: {dataset: {technik: (with_overlap, without_overlap)}} data = defaultdict(dict) # Alle JSON-Dateien einlesen for filename in os.listdir(input_dir): if filename.endswith(".json"): match = filename_pattern.match(filename) if not match: continue dataset, technik = match.groups() filepath = os.path.join(input_dir, filename) with open(filepath, "r", encoding="utf-8") as f: content = json.load(f) # Werte extrahieren face_obj = content.get("face-object-insights", {}) with_overlap = face_obj.get(r"\mathrm{Acc}_{\mathrm{det}}^{\mathrm{with\,overlap}}") without_overlap = face_obj.get(r"\mathrm{Acc}_{\mathrm{det}}^{\mathrm{without\,overlap}}") data[dataset][technik] = (with_overlap, without_overlap) # Für jedes Dataset ein Grouped Bar Chart erstellen for dataset, technik_data in data.items(): techniken = list(technik_data.keys()) with_vals = [technik_data[t][0] for t in techniken] without_vals = [technik_data[t][1] for t in techniken] x = range(len(techniken)) bar_width = 0.35 fig, ax = plt.subplots(figsize=(10, 6)) ax.bar([i - bar_width/2 for i in x], with_vals, width=bar_width, label="mit overlap") ax.bar([i + bar_width/2 for i in x], without_vals, width=bar_width, label="ohne overlap") ax.set_xticks(x) ax.set_xticklabels(techniken, rotation=45, ha="right") ax.set_ylabel("Accuracy") ax.set_title(f"Ergebnisse für Dataset: {dataset}") ax.legend() ax.grid(axis='y', linestyle='--', alpha=0.7) plt.tight_layout() plt.savefig(f"plot_{dataset}.png") plt.close() print("Fertig! Plots gespeichert als 'plot_.png'")