tflite model trainiert und quantisiert
3
.gitignore
vendored
@ -113,4 +113,5 @@ dmypy.json
|
||||
|
||||
runs/
|
||||
Test/
|
||||
yolo_dataset/
|
||||
yolo_dataset/
|
||||
calib_images/
|
||||
BIN
best_int8.tflite
Normal file
42
quantisierung.py
Normal file
@ -0,0 +1,42 @@
|
||||
import tensorflow as tf
|
||||
import numpy as np
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
dir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# --- Pfad zum SavedModel ---
|
||||
saved_model_dir = dir + "/yolo_training/NAO_detector9/weights/best_saved_model"
|
||||
|
||||
# --- Optional: Pfad zu Beispielbildern ---
|
||||
image_dir = dir + "/calib_images" # z. B. 50–100 JPGs aus deinem Datensatz (z. B. NAO-Roboter-Bilder)
|
||||
input_size = (320, 320) # oder (640, 640) je nach deinem Modellinput
|
||||
|
||||
# --- Repräsentative Datenfunktion ---
|
||||
def representative_data_gen():
|
||||
for filename in os.listdir(image_dir):
|
||||
if filename.endswith(".jpg") or filename.endswith(".png"):
|
||||
img = Image.open(os.path.join(image_dir, filename)).convert("RGB")
|
||||
img = img.resize(input_size)
|
||||
img = np.array(img, dtype=np.float32) / 255.0 # normalisieren falls nötig
|
||||
img = np.expand_dims(img, axis=0)
|
||||
yield [img]
|
||||
|
||||
# --- Konverter konfigurieren ---
|
||||
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
|
||||
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
||||
converter.representative_dataset = representative_data_gen
|
||||
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
|
||||
|
||||
# Je nach Ziel-Hardware (z. B. NAO): INT8 in/out oder UINT8
|
||||
converter.inference_input_type = tf.uint8
|
||||
converter.inference_output_type = tf.uint8
|
||||
|
||||
# --- Konvertieren ---
|
||||
quant_model = converter.convert()
|
||||
|
||||
# --- Speichern ---
|
||||
with open("best_int8.tflite", "wb") as f:
|
||||
f.write(quant_model)
|
||||
|
||||
print("✅ INT8-Quantisierung abgeschlossen.")
|
||||
@ -99,14 +99,8 @@ def train_yolo():
|
||||
# OpenVINO Format (optimiert für Intel Hardware)
|
||||
model.export(format='openvino', imgsz=320)
|
||||
|
||||
model.export(
|
||||
format="tflite",
|
||||
dynamic=False,
|
||||
inference_type="uint8",
|
||||
quantize=True,
|
||||
imgsz=320,
|
||||
calibration_data=os.path.join(dir, "calib_images")
|
||||
)
|
||||
# tflite Format
|
||||
model.export(format="tflite",imgsz=320,)
|
||||
|
||||
print("\nTraining abgeschlossen. Die Modelle wurden im 'yolo_training/NAO_detector' Ordner gespeichert.")
|
||||
|
||||
|
||||
BIN
yolo_training/NAO_detector9/F1_curve.png
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
yolo_training/NAO_detector9/PR_curve.png
Normal file
|
After Width: | Height: | Size: 78 KiB |
BIN
yolo_training/NAO_detector9/P_curve.png
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
yolo_training/NAO_detector9/R_curve.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
105
yolo_training/NAO_detector9/args.yaml
Normal file
@ -0,0 +1,105 @@
|
||||
task: detect
|
||||
mode: train
|
||||
model: yolov8n.pt
|
||||
data: yolo_dataset/dataset.yaml
|
||||
epochs: 50
|
||||
time: null
|
||||
patience: 5
|
||||
batch: 16
|
||||
imgsz: 320
|
||||
save: true
|
||||
save_period: -1
|
||||
cache: false
|
||||
device: '0'
|
||||
workers: 8
|
||||
project: yolo_training
|
||||
name: NAO_detector9
|
||||
exist_ok: false
|
||||
pretrained: true
|
||||
optimizer: auto
|
||||
verbose: true
|
||||
seed: 0
|
||||
deterministic: true
|
||||
single_cls: false
|
||||
rect: false
|
||||
cos_lr: false
|
||||
close_mosaic: 10
|
||||
resume: false
|
||||
amp: true
|
||||
fraction: 1.0
|
||||
profile: false
|
||||
freeze: null
|
||||
multi_scale: false
|
||||
overlap_mask: true
|
||||
mask_ratio: 4
|
||||
dropout: 0.0
|
||||
val: true
|
||||
split: val
|
||||
save_json: false
|
||||
conf: null
|
||||
iou: 0.7
|
||||
max_det: 300
|
||||
half: false
|
||||
dnn: false
|
||||
plots: true
|
||||
source: null
|
||||
vid_stride: 1
|
||||
stream_buffer: false
|
||||
visualize: false
|
||||
augment: false
|
||||
agnostic_nms: false
|
||||
classes: null
|
||||
retina_masks: false
|
||||
embed: null
|
||||
show: false
|
||||
save_frames: false
|
||||
save_txt: false
|
||||
save_conf: false
|
||||
save_crop: false
|
||||
show_labels: true
|
||||
show_conf: true
|
||||
show_boxes: true
|
||||
line_width: null
|
||||
format: torchscript
|
||||
keras: false
|
||||
optimize: false
|
||||
int8: false
|
||||
dynamic: false
|
||||
simplify: true
|
||||
opset: null
|
||||
workspace: null
|
||||
nms: false
|
||||
lr0: 0.01
|
||||
lrf: 0.01
|
||||
momentum: 0.937
|
||||
weight_decay: 0.0005
|
||||
warmup_epochs: 3.0
|
||||
warmup_momentum: 0.8
|
||||
warmup_bias_lr: 0.1
|
||||
box: 7.5
|
||||
cls: 0.5
|
||||
dfl: 1.5
|
||||
pose: 12.0
|
||||
kobj: 1.0
|
||||
nbs: 64
|
||||
hsv_h: 0.015
|
||||
hsv_s: 0.7
|
||||
hsv_v: 0.4
|
||||
degrees: 0.0
|
||||
translate: 0.1
|
||||
scale: 0.5
|
||||
shear: 0.0
|
||||
perspective: 0.0
|
||||
flipud: 0.0
|
||||
fliplr: 0.5
|
||||
bgr: 0.0
|
||||
mosaic: 1.0
|
||||
mixup: 0.0
|
||||
cutmix: 0.0
|
||||
copy_paste: 0.0
|
||||
copy_paste_mode: flip
|
||||
auto_augment: randaugment
|
||||
erasing: 0.4
|
||||
cfg: null
|
||||
tracker: botsort.yaml
|
||||
save_dir: yolo_training/NAO_detector9
|
||||
BIN
yolo_training/NAO_detector9/confusion_matrix.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
yolo_training/NAO_detector9/confusion_matrix_normalized.png
Normal file
|
After Width: | Height: | Size: 101 KiB |
BIN
yolo_training/NAO_detector9/labels.jpg
Normal file
|
After Width: | Height: | Size: 186 KiB |
31
yolo_training/NAO_detector9/results.csv
Normal file
@ -0,0 +1,31 @@
|
||||
epoch,time,train/box_loss,train/cls_loss,train/dfl_loss,metrics/precision(B),metrics/recall(B),metrics/mAP50(B),metrics/mAP50-95(B),val/box_loss,val/cls_loss,val/dfl_loss,lr/pg0,lr/pg1,lr/pg2
|
||||
1,24.5837,1.38337,1.59497,1.13299,0.77381,0.63415,0.79174,0.51402,1.07247,1.59311,1.10924,0.000661064,0.000661064,0.000661064
|
||||
2,44.1935,1.37648,1.1011,1.12629,0.47912,0.56098,0.48856,0.29811,1.65133,2.146,1.48548,0.00130144,0.00130144,0.00130144
|
||||
3,63.5209,1.37521,1.00512,1.14473,0.75871,0.76707,0.85137,0.51276,1.45374,1.14832,1.33055,0.00191542,0.00191542,0.00191542
|
||||
4,83.0181,1.39248,0.97729,1.1521,0.72427,0.90244,0.83962,0.55562,1.1063,1.1655,1.1848,0.0018812,0.0018812,0.0018812
|
||||
5,102.099,1.34909,0.9365,1.1294,0.80313,0.82927,0.87456,0.59494,1.10444,0.98597,1.10162,0.0018416,0.0018416,0.0018416
|
||||
6,120.495,1.30565,0.85466,1.10696,0.78937,0.90244,0.88324,0.6495,1.01957,0.99015,1.0765,0.001802,0.001802,0.001802
|
||||
7,139.265,1.29615,0.83925,1.10297,0.81199,0.84285,0.91349,0.69203,0.9179,0.87651,1.0519,0.0017624,0.0017624,0.0017624
|
||||
8,158.55,1.23532,0.78344,1.08741,0.83294,0.8513,0.90222,0.70301,0.93553,0.8022,1.00482,0.0017228,0.0017228,0.0017228
|
||||
9,177.315,1.24022,0.77411,1.07758,0.89615,0.80488,0.92216,0.66249,0.98643,0.82604,1.02006,0.0016832,0.0016832,0.0016832
|
||||
10,195.778,1.22761,0.76174,1.09093,0.77696,0.9347,0.94549,0.74916,0.89332,0.75543,1.02896,0.0016436,0.0016436,0.0016436
|
||||
11,214.175,1.20899,0.74909,1.08335,0.80922,0.87805,0.91758,0.68197,0.89423,0.88144,1.04086,0.001604,0.001604,0.001604
|
||||
12,232.891,1.20618,0.74583,1.07317,0.9041,0.90244,0.94701,0.72502,0.86928,0.74318,0.9874,0.0015644,0.0015644,0.0015644
|
||||
13,251.636,1.18134,0.71034,1.05533,0.8864,0.95162,0.9707,0.75873,0.84101,0.64098,0.99018,0.0015248,0.0015248,0.0015248
|
||||
14,270.239,1.17983,0.70683,1.06267,0.79901,0.90244,0.92739,0.74632,0.74994,0.70678,0.96296,0.0014852,0.0014852,0.0014852
|
||||
15,288.895,1.17521,0.69821,1.06029,0.82494,0.87805,0.90711,0.68548,0.81982,0.72279,0.95689,0.0014456,0.0014456,0.0014456
|
||||
16,307.27,1.15779,0.68632,1.04943,0.92729,0.95122,0.96588,0.76468,0.82413,0.6346,0.99141,0.001406,0.001406,0.001406
|
||||
17,325.407,1.16109,0.6758,1.04592,0.92107,0.95122,0.96739,0.7732,0.7881,0.62989,0.9065,0.0013664,0.0013664,0.0013664
|
||||
18,343.35,1.12661,0.66474,1.04166,0.97356,0.97561,0.98827,0.81068,0.69881,0.55234,0.88231,0.0013268,0.0013268,0.0013268
|
||||
19,361.278,1.12698,0.64788,1.03084,0.94956,0.92683,0.96542,0.7717,0.7068,0.63099,0.92191,0.0012872,0.0012872,0.0012872
|
||||
20,379.226,1.13069,0.65455,1.03885,0.90112,0.97561,0.97418,0.78791,0.70749,0.60267,0.89277,0.0012476,0.0012476,0.0012476
|
||||
21,397.629,1.11647,0.63365,1.0299,0.92627,0.97561,0.9702,0.81019,0.67045,0.62768,0.8665,0.001208,0.001208,0.001208
|
||||
22,416.662,1.09492,0.62911,1.02721,0.95114,0.94962,0.98024,0.81772,0.69665,0.538,0.87337,0.0011684,0.0011684,0.0011684
|
||||
23,435.458,1.11042,0.63233,1.02942,0.91751,0.95122,0.9419,0.80744,0.6747,0.58275,0.86386,0.0011288,0.0011288,0.0011288
|
||||
24,453.303,1.09507,0.61695,1.01568,0.97617,0.99934,0.98929,0.84059,0.60503,0.48919,0.84754,0.0010892,0.0010892,0.0010892
|
||||
25,472.178,1.0891,0.61445,1.01644,0.92973,1,0.97934,0.8638,0.62973,0.48138,0.85107,0.0010496,0.0010496,0.0010496
|
||||
26,491.604,1.08137,0.60952,1.01945,0.93175,0.99902,0.97946,0.83194,0.63044,0.51215,0.87336,0.00101,0.00101,0.00101
|
||||
27,510.376,1.07061,0.59402,1.01434,0.9511,0.94891,0.96358,0.83484,0.60126,0.50725,0.86608,0.0009704,0.0009704,0.0009704
|
||||
28,528.926,1.07173,0.58656,1.00666,0.85579,0.97561,0.95489,0.8313,0.61699,0.53136,0.8611,0.0009308,0.0009308,0.0009308
|
||||
29,547.212,1.0585,0.59106,1.01413,0.90673,1,0.96285,0.80755,0.70054,0.54551,0.89977,0.0008912,0.0008912,0.0008912
|
||||
30,565.478,1.04424,0.57113,1.00423,0.88856,0.97245,0.9692,0.85572,0.61174,0.4804,0.83299,0.0008516,0.0008516,0.0008516
|
||||
|
BIN
yolo_training/NAO_detector9/results.png
Normal file
|
After Width: | Height: | Size: 284 KiB |
BIN
yolo_training/NAO_detector9/train_batch0.jpg
Normal file
|
After Width: | Height: | Size: 231 KiB |
BIN
yolo_training/NAO_detector9/train_batch1.jpg
Normal file
|
After Width: | Height: | Size: 217 KiB |
BIN
yolo_training/NAO_detector9/train_batch2.jpg
Normal file
|
After Width: | Height: | Size: 223 KiB |
BIN
yolo_training/NAO_detector9/val_batch0_labels.jpg
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
yolo_training/NAO_detector9/val_batch0_pred.jpg
Normal file
|
After Width: | Height: | Size: 237 KiB |
BIN
yolo_training/NAO_detector9/weights/best.onnx
Normal file
BIN
yolo_training/NAO_detector9/weights/best.pt
Normal file
BIN
yolo_training/NAO_detector9/weights/best_openvino_model/best.bin
Normal file
7846
yolo_training/NAO_detector9/weights/best_openvino_model/best.xml
Normal file
@ -0,0 +1,22 @@
|
||||
description: Ultralytics best model trained on yolo_dataset/dataset.yaml
|
||||
author: Ultralytics
|
||||
date: '2025-07-31T01:20:11.832379'
|
||||
version: 8.3.154
|
||||
license: AGPL-3.0 License (https://ultralytics.com/license)
|
||||
docs: https://docs.ultralytics.com
|
||||
stride: 32
|
||||
task: detect
|
||||
batch: 1
|
||||
imgsz:
|
||||
- 320
|
||||
- 320
|
||||
names:
|
||||
0: NAO-Roboter
|
||||
args:
|
||||
batch: 1
|
||||
fraction: 1.0
|
||||
half: false
|
||||
int8: false
|
||||
dynamic: false
|
||||
nms: false
|
||||
channels: 3
|
||||
@ -0,0 +1 @@
|
||||
╥═кш°ЙЬ╗s─·С╝©°∙и■ы═²В├⌠б╠Q У╧■в╣У▀у≥(⌠ИЯ∙╡жЫьН2:5233161973706285970
|
||||
@ -0,0 +1,21 @@
|
||||
description: Ultralytics best model trained on yolo_dataset/dataset.yaml
|
||||
author: Ultralytics
|
||||
date: '2025-07-31T01:21:01.673821'
|
||||
version: 8.3.154
|
||||
license: AGPL-3.0 License (https://ultralytics.com/license)
|
||||
docs: https://docs.ultralytics.com
|
||||
stride: 32
|
||||
task: detect
|
||||
batch: 1
|
||||
imgsz:
|
||||
- 320
|
||||
- 320
|
||||
names:
|
||||
0: NAO-Roboter
|
||||
args:
|
||||
batch: 1
|
||||
fraction: 1.0
|
||||
half: false
|
||||
int8: false
|
||||
nms: false
|
||||
channels: 3
|
||||