Skip to content

Commit

Permalink
New:
Browse files Browse the repository at this point in the history
1. Create pipeline [yolov5, yolov8]
  • Loading branch information
aimspot committed Dec 14, 2023
1 parent 46cd977 commit a137857
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
10 changes: 5 additions & 5 deletions ODRS/train_utils/config/custom_config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BATCH_SIZE: 20
BATCH_SIZE: [25, 20]
CLASSES: classes.txt
DATA_PATH: /media/space/ssd_1_tb_evo_sumsung/Work/Warp-D
EPOCHS: 2
DATA_PATH: Warp-D
EPOCHS: [4, 5]
GPU_COUNT: 1
IMG_SIZE: 300
MODEL: ssd
IMG_SIZE: [300, 400]
MODEL: [yolov5l, yolov5s]
SELECT_GPU: 0

CONFIG_PATH: dataset.yaml
Expand Down
51 changes: 41 additions & 10 deletions ODRS/train_utils/custom_train_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ def fit_model(DATA_PATH, CLASSES, IMG_SIZE, BATCH_SIZE, EPOCHS, MODEL, CONFIG_PA
train_ssd(CONFIG_PATH)


def run():
"""
Create config, run learning functions.
"""
config_path = Path(ROOT) / 'ODRS' / 'train_utils' / 'config' / 'custom_config.yaml'
config = loadConfig(config_path)

def prepare_to_train(config, list_parameters):
DATA_PATH = config['DATA_PATH']
CLASSES = config['CLASSES']
IMG_SIZE = config['IMG_SIZE']
Expand All @@ -86,8 +79,46 @@ def run():
GPU_COUNT = config['GPU_COUNT']
SELECT_GPU = config['SELECT_GPU']

fit_model(DATA_PATH, CLASSES, IMG_SIZE, BATCH_SIZE, EPOCHS, MODEL, CONFIG_PATH, SPLIT_TRAIN_VALUE,
SPLIT_VAL_VALUE, GPU_COUNT, SELECT_GPU)
if list_parameters:
for i in range(len(list_parameters[list(list_parameters.keys())[0]])):
current_params = {
'DATA_PATH': DATA_PATH[i] if isinstance(DATA_PATH, list) else DATA_PATH,
'CLASSES': CLASSES[i] if isinstance(CLASSES, list) else CLASSES,
'IMG_SIZE': IMG_SIZE[i] if isinstance(IMG_SIZE, list) else IMG_SIZE,
'BATCH_SIZE': BATCH_SIZE[i] if isinstance(BATCH_SIZE, list) else BATCH_SIZE,
'EPOCHS': EPOCHS[i] if isinstance(EPOCHS, list) else EPOCHS,
'MODEL': MODEL[i] if isinstance(MODEL, list) else MODEL,
'CONFIG_PATH': CONFIG_PATH[i] if isinstance(CONFIG_PATH, list) else CONFIG_PATH,
'SPLIT_TRAIN_VALUE': SPLIT_TRAIN_VALUE[i] if isinstance(SPLIT_TRAIN_VALUE, list) else SPLIT_TRAIN_VALUE,
'SPLIT_VAL_VALUE': SPLIT_VAL_VALUE[i] if isinstance(SPLIT_VAL_VALUE, list) else SPLIT_VAL_VALUE,
'GPU_COUNT': GPU_COUNT[i] if isinstance(GPU_COUNT, list) else GPU_COUNT,
'SELECT_GPU': SELECT_GPU[i] if isinstance(SELECT_GPU, list) else SELECT_GPU
}
fit_model(**current_params)

else:
fit_model(DATA_PATH, CLASSES, IMG_SIZE, BATCH_SIZE, EPOCHS, MODEL, CONFIG_PATH, SPLIT_TRAIN_VALUE,
SPLIT_VAL_VALUE, GPU_COUNT, SELECT_GPU)


def check_dict_arrays_sizes(dictionary):
for key, value in dictionary.items():
if isinstance(value, list):
first_array = next(iter(dictionary.values()))
first_array_size = len(first_array)
current_array_size = len(value)
if current_array_size != first_array_size:
raise ValueError(f"Size mismatch for key '{key}'. Expected size: {first_array_size}, actual size: {current_array_size}")


def run():
config_path = Path(ROOT) / 'ODRS' / 'train_utils' / 'config' / 'custom_config.yaml'
config = loadConfig(config_path)

list_parameters = {key: value for key, value in config.items() if isinstance(value, list)}
check_dict_arrays_sizes(list_parameters)
prepare_to_train(config, list_parameters)


if __name__ == "__main__":
run()
5 changes: 3 additions & 2 deletions ODRS/train_utils/train_model/scripts/yolov5_train.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import subprocess
import time
from pathlib import Path
from ODRS.train_utils.train_model.models.yolov5 import train

Expand Down Expand Up @@ -44,5 +46,4 @@ def train_V5(IMG_SIZE, BATCH_SIZE, EPOCHS, CONFIG_PATH, MODEL_PATH, GPU_COUNT, S
f" --project {CONFIG_PATH.parent}" +
f" --name exp"
)

os.system(full_command)
os.system(full_command)
1 change: 1 addition & 0 deletions ODRS/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

file = Path(__file__).resolve()


def loadConfig(config_file):
with open(config_file) as f:
return load(f, Loader=FullLoader)
Expand Down

0 comments on commit a137857

Please sign in to comment.