Train model on the cloud
Deep learning networks excel at automatically extracting features from large datasets, making them highly effective for tasks like object detection and image segmentation. To apply deep learning to your specific use case, you first need to understand how to train a model using known data.
Training models in the cloud
Use this workflow to train a YOLOv8 model in Ultralytics, export it to TFLite, optimize it with Vela, and download the final file.
Start training
Paste this into a new cell.
If the original command uses export, replace it with os.environ[...].
Also add ! before yolo.
import os
# Install ultralytics to get the 'yolo' command
!pip install ultralytics
# Set the API key using os.environ for persistence within the Python process
os.environ['ULTRALYTICS_API_KEY'] = '(YOUR_API_KEY)'
!yolo train \
model="ul://ultralytics/yolov8/yolov8n" \
data="ul://ultralytics/datasets/coco8" \
task="detect" \
epochs=100 \
batch=-1 \
imgsz=640 \
project="(your-name)/example-project"For faster training, change the Colab runtime to T4 GPU.
After you verify the command, run the cell and wait for training to finish.
Export the best model to TFLite
Run this cell after training completes.
Replace (your-name) with your Ultralytics username.
from ultralytics import YOLO
# Load the best trained model
model = YOLO('runs/detect/(your-name)/example-project/train/weights/best.pt')
# Export the model to TFLite format with int8 quantization
model.export(
format='tflite',
imgsz=192,
int8=True
)
print("Model exported to TFLite (int8) successfully!")
print("The exported model should be in the 'runs/detect/train/weights' directory.")Create the Vela config
Paste this into a new cell and run it.
%%writefile vela_config.ini
; file: my_vela_cfg.ini ;
; Vela configuration file ;
; System Configuration
; My_Sys_Cfg
[System_Config.My_Sys_Cfg]
core_clock=400e6
axi0_port=Sram
axi1_port=OffChipFlash
Sram_clock_scale=1.0
Sram_burst_length=32
Sram_read_latency=16
Sram_write_latency=16
Dram_clock_scale=0.75
Dram_burst_length=128
Dram_read_latency=500
Dram_write_latency=250
OnChipFlash_clock_scale=0.25
OffChipFlash_clock_scale=0.015625
OffChipFlash_burst_length=32
OffChipFlash_read_latency=64
OffChipFlash_write_latency=64
; -----------------------------------------------------------------------------
; Memory Mode
; My_Mem_Mode_Parent
[Memory_Mode.My_Mem_Mode_Parent]
const_mem_area=Axi1
arena_mem_area=Axi0
cache_mem_area=Axi0Optimize the TFLite model with Vela
Run this command in a new cell.
Replace (your-name) with your Ultralytics username.
!vela --accelerator-config ethos-u55-64 --config vela_config.ini --system-config My_Sys_Cfg --memory-mode My_Mem_Mode_Parent --output-dir /content /content/runs/detect/(your-name)/example-project/train/weights/best_int8.tfliteResult
After you complete the workflow, you should have an exported and Vela-optimized model ready to download and deploy.
Your final output should be best_int8_vela.tflite.
Examples:
Example exported model output in Colab.
Example optimized model file ready for download.
Last updated