app.py
Browse files
app.py
CHANGED
|
@@ -6,17 +6,29 @@ import os
|
|
| 6 |
import tkinter as tk
|
| 7 |
from PIL import Image
|
| 8 |
import json
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def image_generator(
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Create the generator
|
| 22 |
image_gen = image_generator(directory_path)
|
|
@@ -24,7 +36,7 @@ image_gen = image_generator(directory_path)
|
|
| 24 |
def record_input(fname:str, label:str):
|
| 25 |
if label != "Pass":
|
| 26 |
output = {"fname": fname, "label": label}
|
| 27 |
-
with open("
|
| 28 |
json.dump(output, f)
|
| 29 |
f.write("\n")
|
| 30 |
fname, image = next(image_gen)
|
|
|
|
| 6 |
import tkinter as tk
|
| 7 |
from PIL import Image
|
| 8 |
import json
|
| 9 |
+
from datasets import load_dataset
|
| 10 |
|
| 11 |
+
directory_path = load_dataset("HuberDa/Labeltest")
|
| 12 |
+
print("Spaltennamen:", directory_path['train'].column_names)
|
| 13 |
+
print("Erstes Beispiel im Train-Split:", directory_path['train'][0])
|
| 14 |
+
count = 0
|
| 15 |
|
| 16 |
+
def image_generator(hf_dataset, split="train"):
|
| 17 |
+
image_column = None
|
| 18 |
+
for col in hf_dataset[split].column_names:
|
| 19 |
+
if isinstance(hf_dataset[split][0][col], np.ndarray) or isinstance(hf_dataset[split][0][col], Image.Image):
|
| 20 |
+
image_column = col
|
| 21 |
+
break
|
| 22 |
+
|
| 23 |
+
if image_column is None:
|
| 24 |
+
raise ValueError("Keine Bildspalte gefunden!")
|
| 25 |
|
| 26 |
+
# Schleife durch das Dataset und generiere Bild-Arrays
|
| 27 |
+
for example in hf_dataset[split]:
|
| 28 |
+
image = example[image_column] # Greife auf das Bild zu
|
| 29 |
+
image_array = np.array(image) # Konvertiere es in ein NumPy-Array
|
| 30 |
+
filename = example['id'] if 'id' in example else "unknown"
|
| 31 |
+
yield filename, image_array
|
| 32 |
|
| 33 |
# Create the generator
|
| 34 |
image_gen = image_generator(directory_path)
|
|
|
|
| 36 |
def record_input(fname:str, label:str):
|
| 37 |
if label != "Pass":
|
| 38 |
output = {"fname": fname, "label": label}
|
| 39 |
+
with open("output.txt", 'a') as f:
|
| 40 |
json.dump(output, f)
|
| 41 |
f.write("\n")
|
| 42 |
fname, image = next(image_gen)
|