export_mobile.py 859 B

123456789101112131415161718192021222324
  1. from ultralytics import YOLO
  2. import os
  3. # 1. Load your high-accuracy PC model
  4. model_path = 'best.pt'
  5. if not os.path.exists(model_path):
  6. print(f"Error: {model_path} not found.")
  7. else:
  8. model = YOLO(model_path)
  9. # 2. Export to TFLite with NMS and Quantization
  10. # 'int8' optimization allows the model to leverage mobile NPUs
  11. # 'nms' handles the overlapping box logic natively on-chip
  12. # Note: Exporting to TFLite with int8 might require dataset for calibration or it might use dynamic range quantization if no data is provided.
  13. # Ultralytics handle's calibration if 'data' is provided in export.
  14. model.export(
  15. format='tflite',
  16. int8=True,
  17. nms=True,
  18. imgsz=640,
  19. data='unified_dataset/data.yaml' # For quantization calibration
  20. )
  21. print("Mobile assets generated in: best_saved_model/")