Alleyp commited on
Commit
7b98a3a
Β·
1 Parent(s): 4205621

ref: update somes structures blabla and adjust training script with result saving

Browse files
Files changed (2) hide show
  1. Readme.md +1 -1
  2. scripts/train.py +36 -32
Readme.md CHANGED
@@ -32,7 +32,7 @@ Total de arquivos em FASDD_UAV: 25097
32
 
33
  # Detalhes da estrutura pra treino CV e UAV
34
  ```
35
- data/FASDD_MERGED/
36
  β”œβ”€β”€ images/
37
  β”‚ β”œβ”€β”€ train/
38
  β”‚ β”œβ”€β”€ val/
 
32
 
33
  # Detalhes da estrutura pra treino CV e UAV
34
  ```
35
+ data/FASDD/
36
  β”œβ”€β”€ images/
37
  β”‚ β”œβ”€β”€ train/
38
  β”‚ β”œβ”€β”€ val/
scripts/train.py CHANGED
@@ -1,48 +1,52 @@
 
1
  from ultralytics import YOLO
 
 
 
2
 
3
- def train_yolo_model(data_path, model, epochs=10, batch_size=32, imgsz=320):
4
  """
5
- Train YOLO model with optimized parameters for fastest training (testing purposes)
6
-
7
- Args:
8
- data_path: Path to dataset YAML file
9
- model: Model size ('yolov9n.pt' is fastest, 'yolov9s.pt' for better accuracy)
10
- epochs: Number of training epochs (10-20 for quick tests)
11
- batch_size: Batch size (16-64 depending on GPU memory)
12
- imgsz: Image size (320 fastest, 640 standard, 1280 highest quality)
13
  """
14
- # Load a YOLO model
15
  model = YOLO(model)
16
 
17
- # Train the model with optimized parameters for speed
18
  results = model.train(
19
- data=data_path,
20
  epochs=epochs,
21
  batch=batch_size,
22
  imgsz=imgsz,
23
- device='cpu', # Change to 'cuda' or '0' if you have a GPU
24
- workers=4, # Number of dataloader workers
25
- cache=True, # Cache images for faster training
26
- amp=True, # Automatic Mixed Precision (faster on modern GPUs)
27
- patience=5, # Early stopping patience
28
- save_period=5, # Save checkpoint every 5 epochs
29
- plots=False, # Disable plots to save time
30
  verbose=True
31
  )
32
-
 
33
  return results
34
 
35
- if __name__ == "__main__":
36
- data_path = "fasdd.yaml" # Path to the dataset configuration file
 
 
 
 
37
 
38
- # For fastest training (testing purposes):
39
- train_yolo_model(data_path, model='yolov9s.pt', epochs=5, batch_size=64, imgsz=320)
 
 
 
40
 
41
- # For balanced speed/accuracy (uncomment to use):
42
- # train_yolo_model(data_path, epochs=20, batch_size=32, imgsz=480)
43
-
44
- # For full training (uncomment to use):
45
- # train_yolo_model(data_path, model='yolov9s.pt', epochs=100, batch_size=16, imgsz=640)
46
-
47
- # For balanced speed/accuracy (uncomment to use):
48
- # train_yolo_model(data_path, epochs=20, batch_size=32, imgsz=480)
 
 
1
+
2
  from ultralytics import YOLO
3
+ from datetime import datetime
4
+ import os
5
+ import shutil
6
 
7
+ def train_yolo_model(data_path, model='yolov9s.pt', epochs=10, batch_size=8, imgsz=320):
8
  """
9
+ Train YOLOv9s model on Raspberry Pi 5 with light settings and CSV export.
 
 
 
 
 
 
 
10
  """
 
11
  model = YOLO(model)
12
 
 
13
  results = model.train(
14
+ data=data_path,
15
  epochs=epochs,
16
  batch=batch_size,
17
  imgsz=imgsz,
18
+ device='cpu',
19
+ workers=2,
20
+ cache=True, # PS: como True consome RAM, mas acelera. Desligar se travar
21
+ amp=False,
22
+ patience=5,
23
+ save_period=5,
24
+ plots=False,
25
  verbose=True
26
  )
27
+
28
+ save_results_csv()
29
  return results
30
 
31
+ def save_results_csv():
32
+ now = datetime.now().strftime("%Y%m%d_%H%M%S")
33
+ source = "runs/detect/train/results.csv"
34
+ target_dir = "training_logs"
35
+ target = f"{target_dir}/yolov9s_{now}.csv"
36
+ os.makedirs(target_dir, exist_ok=True)
37
 
38
+ if os.path.exists(source):
39
+ shutil.copy(source, target)
40
+ print(f"βœ… Training metrics saved to: {target}")
41
+ else:
42
+ print("⚠️ results.csv not found. Was training successful?")
43
 
44
+ if __name__ == "__main__":
45
+ data_path = "fasdd.yaml"
46
+ train_yolo_model(
47
+ data_path=data_path,
48
+ model='yolov9s.pt',
49
+ epochs=10,
50
+ batch_size=8, # Adjust if it crashes
51
+ imgsz=320 # Test 416 later
52
+ )