Skip to content

Commit

Permalink
added models and reports
Browse files Browse the repository at this point in the history
  • Loading branch information
RihabFekii committed Apr 3, 2023
1 parent be28477 commit a6d686c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 7 deletions.
25 changes: 25 additions & 0 deletions dvc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
schema: '2.0'
stages:
train:
cmd: python src/train.py
deps:
- path: data/raw/wildfire-raw-yolov8
md5: ffe9083905cf64817ca61146b3356bb6.dir
size: 28867246
nfiles: 1482
- path: src/params.yaml
md5: a0c123b909925d3386149e8b024832a0
size: 215
- path: src/train.py
md5: d2675f1ccbf8af2b7c25485e47c4c783
size: 990
- path: src/utils.py
md5: e1585268f1a61213ac6e51f7abf0d47f
size: 1090
outs:
- path: models/model.pt
md5: 8198bbc4220f971f09595a135320f968
size: 6226104
- path: reports/train_metrics.csv
md5: fb687ccb189b9b1fe433eac7c2b4304f
size: 672
6 changes: 5 additions & 1 deletion dvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ stages:
- data/raw/wildfire-raw-yolov8
- src/train.py
- src/params.yaml
- src/utils.py
outs:
- runs/:
- models/model.pt:
persist: true
metrics:
- reports/train_metrics.csv:
cache: false
1 change: 1 addition & 0 deletions models/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/model.pt
Binary file added reports/train_confision_matric.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions reports/train_metrics.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
epoch, 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
0, 1.9822, 4.1505, 1.6088, 0.00279, 0.83673, 0.04395, 0.0187, 2.0868, 4.2883, 1.5972, 0.070462, 0.0032821, 0.0032821
Empty file added src/__init__.py
Empty file.
19 changes: 13 additions & 6 deletions src/train.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from ultralytics import YOLO
import yaml
from pathlib import Path
import os
from pathlib import Path

import yaml
from ultralytics import YOLO

from utils import save_metrics, save_model


ROOT_DIR = Path(__file__).resolve().parents[1] # root directory absolute path
DATA_DIR = os.path.join(ROOT_DIR, "data/raw/wildfire-raw-yolov8")
DATA_YAML = os.path.join(DATA_DIR, "data.yaml")
print(DATA_YAML)


if __name__ == '__main__':
Expand All @@ -31,8 +33,13 @@
name=params['name']
)

# evaluate model
model.val()
# save model
save_model(experiment_name=params['name'])

# save metrics
save_metrics(experiment_name=params['name'])





Expand Down
27 changes: 27 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil
from pathlib import Path

ROOT_DIR = Path(__file__).resolve().parents[1] # root directory absolute path


def save_model(experiment_name: str) -> None:
""" saves the weights of trained model to the models directory """
if os.path.isdir('runs'):
model_weights = experiment_name + "/weights/best.pt"
path_model_weights = os.path.join(ROOT_DIR, "runs/detect", model_weights)

shutil.copy(src=path_model_weights, dst=f'{ROOT_DIR}/models/model.pt')


def save_metrics(experiment_name: str) -> None:
""" saves training metrics and confusion matrix to the reports directory """
if os.path.isdir('runs'):
path_metrics = os.path.join(ROOT_DIR, "runs/detect", experiment_name)
# save experiment training metrics
shutil.copy(src=f'{path_metrics}/results.csv', dst=f'{ROOT_DIR}/reports/train_metrics.csv')

# save the confusion matrix associated to the training experiment
shutil.copy(src=f'{path_metrics}/confusion_matrix.png', dst=f'{ROOT_DIR}/reports/train_confision_matric.png')


0 comments on commit a6d686c

Please sign in to comment.