Spaces:
Runtime error
Runtime error
Yusuf commited on
Commit ·
3f67469
1
Parent(s): 1cb71bc
clearml sub-folders & device check
Browse files
dataPrep/data_preparation.py
CHANGED
|
@@ -45,8 +45,9 @@ if torch.cuda.is_available():
|
|
| 45 |
|
| 46 |
|
| 47 |
# ----- ClearML Setup -----
|
|
|
|
| 48 |
task = Task.init(
|
| 49 |
-
project_name='
|
| 50 |
task_name='Data Preparation',
|
| 51 |
task_type=Task.TaskTypes.data_processing
|
| 52 |
)
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
# ----- ClearML Setup -----
|
| 48 |
+
project_name = "Small Group Project"
|
| 49 |
task = Task.init(
|
| 50 |
+
project_name=f'{project_name}/Data Preparation',
|
| 51 |
task_name='Data Preparation',
|
| 52 |
task_type=Task.TaskTypes.data_processing
|
| 53 |
)
|
testingModel/run_testing.py
CHANGED
|
@@ -13,7 +13,7 @@ subset_loaders, full_loaders, data_prep_metadata = extract_latest_data_task(proj
|
|
| 13 |
|
| 14 |
# -------- ClearML Testing Task Setup --------
|
| 15 |
testing_task = Task.init(
|
| 16 |
-
project_name="
|
| 17 |
task_name="Model Testing",
|
| 18 |
task_type=Task.TaskTypes.testing,
|
| 19 |
reuse_last_task_id=False,
|
|
@@ -38,6 +38,12 @@ training_task = Task.get_task(task_id=testing_config["model_train_id"])
|
|
| 38 |
model_artifact = training_task.artifacts.get("best_model")
|
| 39 |
model_path = model_artifact.get_local_copy()
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
model = modelOne()
|
| 42 |
state_dict = torch.load(model_path, map_location="cpu") # Load to CPU first
|
| 43 |
model.load_state_dict(state_dict)
|
|
|
|
| 13 |
|
| 14 |
# -------- ClearML Testing Task Setup --------
|
| 15 |
testing_task = Task.init(
|
| 16 |
+
project_name=f"{project_name}/Model Testing",
|
| 17 |
task_name="Model Testing",
|
| 18 |
task_type=Task.TaskTypes.testing,
|
| 19 |
reuse_last_task_id=False,
|
|
|
|
| 38 |
model_artifact = training_task.artifacts.get("best_model")
|
| 39 |
model_path = model_artifact.get_local_copy()
|
| 40 |
|
| 41 |
+
# Reference training metadata
|
| 42 |
+
training_hyperparams = training_task.get_parameters_as_dict()
|
| 43 |
+
testing_task.connect(training_hyperparams['General'], name="training_metadata_READONLY")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
# -------- Rebuild the ML model --------
|
| 47 |
model = modelOne()
|
| 48 |
state_dict = torch.load(model_path, map_location="cpu") # Load to CPU first
|
| 49 |
model.load_state_dict(state_dict)
|
trainingModel/{Training.py → helpers/Training.py}
RENAMED
|
File without changes
|
trainingModel/run_training.py
CHANGED
|
@@ -4,7 +4,7 @@ from dataPrep.helpers.clearml_data import extract_latest_data_task
|
|
| 4 |
|
| 5 |
import torch
|
| 6 |
from models.modelOne import modelOne
|
| 7 |
-
from trainingModel.Training import train_model
|
| 8 |
|
| 9 |
|
| 10 |
# -------------- Load Data --------------
|
|
@@ -14,7 +14,7 @@ subset_loaders, full_loaders, data_prep_metadata = extract_latest_data_task(proj
|
|
| 14 |
|
| 15 |
# -------- ClearML Training Task Setup --------
|
| 16 |
training_task = Task.init(
|
| 17 |
-
project_name="
|
| 18 |
task_name="Model Training",
|
| 19 |
reuse_last_task_id=False,
|
| 20 |
)
|
|
@@ -26,7 +26,7 @@ training_task.connect(data_prep_metadata, name="data_prep_metadata_READONLY")
|
|
| 26 |
# Training parameters - Modify these to experiment
|
| 27 |
training_config = {
|
| 28 |
"num_classes": 39,
|
| 29 |
-
"n_epochs":
|
| 30 |
"learning_rate": 1e-3,
|
| 31 |
"optimizer": "adam",
|
| 32 |
"save_path": "best_model.pt",
|
|
@@ -37,7 +37,12 @@ training_task.connect(training_config)
|
|
| 37 |
# -------- Build the ML model --------
|
| 38 |
model = modelOne(noOfClasses=training_config["num_classes"])
|
| 39 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# ------- Train the model (on subset for now) -------
|
| 43 |
|
|
|
|
| 4 |
|
| 5 |
import torch
|
| 6 |
from models.modelOne import modelOne
|
| 7 |
+
from trainingModel.helpers.Training import train_model
|
| 8 |
|
| 9 |
|
| 10 |
# -------------- Load Data --------------
|
|
|
|
| 14 |
|
| 15 |
# -------- ClearML Training Task Setup --------
|
| 16 |
training_task = Task.init(
|
| 17 |
+
project_name=f"{project_name}/Model Training",
|
| 18 |
task_name="Model Training",
|
| 19 |
reuse_last_task_id=False,
|
| 20 |
)
|
|
|
|
| 26 |
# Training parameters - Modify these to experiment
|
| 27 |
training_config = {
|
| 28 |
"num_classes": 39,
|
| 29 |
+
"n_epochs": 1,
|
| 30 |
"learning_rate": 1e-3,
|
| 31 |
"optimizer": "adam",
|
| 32 |
"save_path": "best_model.pt",
|
|
|
|
| 37 |
# -------- Build the ML model --------
|
| 38 |
model = modelOne(noOfClasses=training_config["num_classes"])
|
| 39 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 40 |
+
model.to(device)
|
| 41 |
|
| 42 |
+
# Print device info
|
| 43 |
+
print(f"\n**Using device: {device}**\n")
|
| 44 |
+
if device.type == 'cuda':
|
| 45 |
+
print(f"GPU Name: {torch.cuda.get_device_name(0)}")
|
| 46 |
|
| 47 |
# ------- Train the model (on subset for now) -------
|
| 48 |
|