init repo
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.keras filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
111
.gitignore
vendored
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# Virtual environments
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env/
|
||||||
|
.venv/
|
||||||
|
.env/
|
||||||
|
.ENV/
|
||||||
|
ENV.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
# Flask stuff
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# System-specific
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# dotenv
|
||||||
|
*.env
|
||||||
|
.env.*
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
#Models
|
||||||
|
*.keras
|
||||||
|
*.h5
|
||||||
101
train_yolo
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from ultralytics import YOLO
|
||||||
|
import yaml
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def verify_images(dataset_path):
|
||||||
|
"""Überprüfe alle Bilder auf Lesbarkeit und korrekte Dimensionen."""
|
||||||
|
print("\nÜberprüfe Bilder...")
|
||||||
|
corrupted = []
|
||||||
|
for split in ['train', 'val']:
|
||||||
|
img_dir = dataset_path / split / 'images'
|
||||||
|
if not img_dir.exists():
|
||||||
|
continue
|
||||||
|
|
||||||
|
for img_path in img_dir.glob('*'):
|
||||||
|
try:
|
||||||
|
img = cv2.imread(str(img_path))
|
||||||
|
if img is None:
|
||||||
|
raise ValueError("Bild konnte nicht gelesen werden")
|
||||||
|
if img.shape[0] < 10 or img.shape[1] < 10:
|
||||||
|
raise ValueError("Bild ist zu klein")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Warnung: Problem mit {img_path}: {str(e)}")
|
||||||
|
corrupted.append(img_path)
|
||||||
|
|
||||||
|
if corrupted:
|
||||||
|
print(f"\nGefundene problematische Bilder: {len(corrupted)}")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def create_yolo_dataset():
|
||||||
|
"""Erstelle die YOLO-Dateistruktur und konvertiere die Annotationen."""
|
||||||
|
try:
|
||||||
|
# Erstelle Verzeichnisse
|
||||||
|
dataset_path = Path('yolo_dataset')
|
||||||
|
if not dataset_path.exists():
|
||||||
|
print("Fehler: YOLO Dataset nicht gefunden! Bitte führen Sie zuerst convert_annotations.py aus.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Überprüfe Bilder
|
||||||
|
if not verify_images(dataset_path):
|
||||||
|
print("Warnung: Einige Bilder könnten problematisch sein!")
|
||||||
|
|
||||||
|
# Erstelle dataset.yaml
|
||||||
|
dataset_yaml = {
|
||||||
|
'path': str(dataset_path.absolute()),
|
||||||
|
'train': 'train/images',
|
||||||
|
'val': 'val/images',
|
||||||
|
'names': {
|
||||||
|
0: 'NAO-Roboter'
|
||||||
|
},
|
||||||
|
'nc': 1 # Anzahl der Klassen
|
||||||
|
}
|
||||||
|
|
||||||
|
yaml_path = dataset_path / 'dataset.yaml'
|
||||||
|
with open(yaml_path, 'w') as f:
|
||||||
|
yaml.dump(dataset_yaml, f)
|
||||||
|
|
||||||
|
return str(yaml_path)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Fehler beim Erstellen des Datasets: {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def train_yolo():
|
||||||
|
"""Trainiere das YOLOv8 Modell."""
|
||||||
|
# Erstelle und konfiguriere das Dataset
|
||||||
|
dataset_yaml = create_yolo_dataset()
|
||||||
|
|
||||||
|
# Initialisiere das Modell
|
||||||
|
model = YOLO('yolov8n.pt') # Verwende das kleine YOLOv8 Modell
|
||||||
|
|
||||||
|
# Trainiere das Modell
|
||||||
|
results = model.train(
|
||||||
|
data=dataset_yaml,
|
||||||
|
epochs=50,
|
||||||
|
imgsz=640, # Bildgröße
|
||||||
|
batch=16, # Batch-Größe
|
||||||
|
device='cpu', # Verwende CPU (oder 'cuda' für GPU)
|
||||||
|
patience=5, # Early Stopping
|
||||||
|
save=True, # Speichere die besten Gewichte
|
||||||
|
project='yolo_training', # Projektname
|
||||||
|
name='NAO_detector', # Experimentname
|
||||||
|
)
|
||||||
|
|
||||||
|
# Exportiere das Modell für den NAO
|
||||||
|
print("\nExportiere Modell in verschiedene Formate...")
|
||||||
|
|
||||||
|
# ONNX Format (gut für eingebettete Systeme)
|
||||||
|
model.export(format='onnx', imgsz=640)
|
||||||
|
|
||||||
|
# OpenVINO Format (optimiert für Intel Hardware)
|
||||||
|
model.export(format='openvino', imgsz=640)
|
||||||
|
|
||||||
|
print("\nTraining abgeschlossen. Die Modelle wurden im 'yolo_training/NAO_detector' Ordner gespeichert.")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
train_yolo()
|
||||||
6
yolo_dataset/dataset.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
names:
|
||||||
|
0: NAO-Roboter
|
||||||
|
nc: 1
|
||||||
|
path: C:\Users\vincent.hanewinkel\Projekts\Hochschule\NAO_Roboter_Erkennung\yolo_dataset
|
||||||
|
train: train/images
|
||||||
|
val: val/images
|
||||||
BIN
yolo_dataset/train/images/20250508_155517.jpg
Normal file
|
After Width: | Height: | Size: 9.1 MiB |
BIN
yolo_dataset/train/images/20250508_155525.jpg
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
yolo_dataset/train/images/20250508_155543.jpg
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
yolo_dataset/train/images/20250508_155558.jpg
Normal file
|
After Width: | Height: | Size: 8.9 MiB |
BIN
yolo_dataset/train/images/20250508_155559.jpg
Normal file
|
After Width: | Height: | Size: 9.7 MiB |
BIN
yolo_dataset/train/images/20250508_155604.jpg
Normal file
|
After Width: | Height: | Size: 8.8 MiB |
BIN
yolo_dataset/train/images/20250508_160256.jpg
Normal file
|
After Width: | Height: | Size: 9.7 MiB |
BIN
yolo_dataset/train/images/20250508_160257.jpg
Normal file
|
After Width: | Height: | Size: 9.4 MiB |
BIN
yolo_dataset/train/images/20250508_160303.jpg
Normal file
|
After Width: | Height: | Size: 9.6 MiB |
BIN
yolo_dataset/train/images/20250508_160305.jpg
Normal file
|
After Width: | Height: | Size: 9.4 MiB |
BIN
yolo_dataset/train/images/20250508_160309.jpg
Normal file
|
After Width: | Height: | Size: 11 MiB |
BIN
yolo_dataset/train/images/20250508_160310.jpg
Normal file
|
After Width: | Height: | Size: 11 MiB |
BIN
yolo_dataset/train/images/20250508_160311.jpg
Normal file
|
After Width: | Height: | Size: 11 MiB |
BIN
yolo_dataset/train/images/20250508_160319.jpg
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
yolo_dataset/train/images/20250508_160321.jpg
Normal file
|
After Width: | Height: | Size: 10 MiB |
BIN
yolo_dataset/train/images/20250508_160329.jpg
Normal file
|
After Width: | Height: | Size: 8.8 MiB |
BIN
yolo_dataset/train/images/20250508_160338.jpg
Normal file
|
After Width: | Height: | Size: 8.1 MiB |
BIN
yolo_dataset/train/images/20250508_160510.jpg
Normal file
|
After Width: | Height: | Size: 14 MiB |
BIN
yolo_dataset/train/images/20250508_160518.jpg
Normal file
|
After Width: | Height: | Size: 16 MiB |
BIN
yolo_dataset/train/images/20250508_160542.jpg
Normal file
|
After Width: | Height: | Size: 8.9 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155503372.jpg
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155507523.jpg
Normal file
|
After Width: | Height: | Size: 5.2 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155509975.jpg
Normal file
|
After Width: | Height: | Size: 5.2 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155513869.jpg
Normal file
|
After Width: | Height: | Size: 3.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155518181.jpg
Normal file
|
After Width: | Height: | Size: 4.2 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155520915.jpg
Normal file
|
After Width: | Height: | Size: 3.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155524377.jpg
Normal file
|
After Width: | Height: | Size: 4.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155527183.jpg
Normal file
|
After Width: | Height: | Size: 4.9 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155531447.jpg
Normal file
|
After Width: | Height: | Size: 4.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155544880.jpg
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155547000.jpg
Normal file
|
After Width: | Height: | Size: 4.4 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155550957.jpg
Normal file
|
After Width: | Height: | Size: 4.3 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155552858.jpg
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155554665.jpg
Normal file
|
After Width: | Height: | Size: 3.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155603815.jpg
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_155605750.jpg
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160257364.jpg
Normal file
|
After Width: | Height: | Size: 3.4 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160257904.jpg
Normal file
|
After Width: | Height: | Size: 4.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160300697.jpg
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160303450.jpg
Normal file
|
After Width: | Height: | Size: 4.0 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160311394.jpg
Normal file
|
After Width: | Height: | Size: 4.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160327470.jpg
Normal file
|
After Width: | Height: | Size: 5.3 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160327912.jpg
Normal file
|
After Width: | Height: | Size: 4.3 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160332839.jpg
Normal file
|
After Width: | Height: | Size: 4.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160354444.jpg
Normal file
|
After Width: | Height: | Size: 4.3 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160354487.jpg
Normal file
|
After Width: | Height: | Size: 7.2 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160401892.jpg
Normal file
|
After Width: | Height: | Size: 5.2 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160442267.jpg
Normal file
|
After Width: | Height: | Size: 3.6 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160443923.jpg
Normal file
|
After Width: | Height: | Size: 5.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160449377.jpg
Normal file
|
After Width: | Height: | Size: 5.8 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160451480.jpg
Normal file
|
After Width: | Height: | Size: 3.1 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160509469.jpg
Normal file
|
After Width: | Height: | Size: 6.9 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160512514.jpg
Normal file
|
After Width: | Height: | Size: 5.8 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160517445.jpg
Normal file
|
After Width: | Height: | Size: 7.0 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160536788.jpg
Normal file
|
After Width: | Height: | Size: 4.0 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160540012.jpg
Normal file
|
After Width: | Height: | Size: 2.9 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160541790.jpg
Normal file
|
After Width: | Height: | Size: 4.5 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160547020.jpg
Normal file
|
After Width: | Height: | Size: 5.3 MiB |
BIN
yolo_dataset/train/images/IMG_20250508_160548560.jpg
Normal file
|
After Width: | Height: | Size: 4.9 MiB |
BIN
yolo_dataset/train/images/upper_103593.jpg
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
yolo_dataset/train/images/upper_103629.jpg
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
yolo_dataset/train/images/upper_103669.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
yolo_dataset/train/images/upper_103706.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
yolo_dataset/train/images/upper_103709.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
yolo_dataset/train/images/upper_103719.jpg
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
yolo_dataset/train/images/upper_103739.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
yolo_dataset/train/images/upper_103742.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
yolo_dataset/train/images/upper_103749.jpg
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
yolo_dataset/train/images/upper_103799.jpg
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
yolo_dataset/train/images/upper_103802.jpg
Normal file
|
After Width: | Height: | Size: 71 KiB |
BIN
yolo_dataset/train/images/upper_103809.jpg
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
yolo_dataset/train/images/upper_103826.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
BIN
yolo_dataset/train/images/upper_103829.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
yolo_dataset/train/images/upper_103832.jpg
Normal file
|
After Width: | Height: | Size: 90 KiB |
BIN
yolo_dataset/train/images/upper_103869.jpg
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
yolo_dataset/train/images/upper_103892.jpg
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
yolo_dataset/train/images/upper_103896.jpg
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
yolo_dataset/train/images/upper_103902.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
yolo_dataset/train/images/upper_104049.jpg
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
yolo_dataset/train/images/upper_104056.jpg
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
yolo_dataset/train/images/upper_104066.jpg
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
yolo_dataset/train/images/upper_104072.jpg
Normal file
|
After Width: | Height: | Size: 69 KiB |
BIN
yolo_dataset/train/images/upper_104202.jpg
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
yolo_dataset/train/images/upper_104212.jpg
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
yolo_dataset/train/images/upper_104219.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
yolo_dataset/train/images/upper_104286.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
yolo_dataset/train/images/upper_104319.jpg
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
yolo_dataset/train/images/upper_104359.jpg
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
yolo_dataset/train/images/upper_104462.jpg
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
yolo_dataset/train/images/upper_104502.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
yolo_dataset/train/images/upper_104509.jpg
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
yolo_dataset/train/images/upper_104535.jpg
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
yolo_dataset/train/images/upper_104579.jpg
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
yolo_dataset/train/images/upper_104595.jpg
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
yolo_dataset/train/images/upper_104602.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
yolo_dataset/train/images/upper_104609.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |