Upload run_experiments.py
Browse files- run_experiments.py +77 -0
run_experiments.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import argparse
|
| 3 |
+
|
| 4 |
+
# python run_experiments.py --dataset "Birds-Nest" --model yolov10n yolov10s yolov10m yolov10l
|
| 5 |
+
|
| 6 |
+
def run_experiment(base_command, run_mode, use_pretrained):
|
| 7 |
+
"""
|
| 8 |
+
Constructs and runs a single experiment command.
|
| 9 |
+
"""
|
| 10 |
+
command = base_command + ["--run", run_mode]
|
| 11 |
+
if use_pretrained:
|
| 12 |
+
command.append("--pretrained")
|
| 13 |
+
|
| 14 |
+
print("="*80)
|
| 15 |
+
print(f"Starting run: {run_mode}")
|
| 16 |
+
print(f"Command: {' '.join(command)}")
|
| 17 |
+
print("="*80)
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
# subprocess.run is a blocking call, ensuring sequential execution.
|
| 21 |
+
subprocess.run(command, check=True)
|
| 22 |
+
print(f"\nSUCCESS: Run '{run_mode}' completed.\n")
|
| 23 |
+
except subprocess.CalledProcessError as e:
|
| 24 |
+
print(f"\nERROR: Run '{run_mode}' failed with exit code {e.returncode}.\n")
|
| 25 |
+
# Decide if you want to stop all subsequent runs on failure
|
| 26 |
+
# raise e # Uncomment to stop the entire sequence on error
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
"""
|
| 30 |
+
Parses arguments and launches a sequence of training experiments for each specified model.
|
| 31 |
+
"""
|
| 32 |
+
parser = argparse.ArgumentParser(description="Run a sequence of YOLO training experiments.")
|
| 33 |
+
|
| 34 |
+
# Define arguments that will be common to all training runs
|
| 35 |
+
parser.add_argument('--dataset', type=str, required=True, choices=["Birds-Nest", "Common-VALID", "Electric-Substation", "InsPLAD-det"], help='Dataset name to be used.')
|
| 36 |
+
parser.add_argument("--model", nargs='+', required=True, choices=["yolov8n", "yolov8s", "yolov8m", "yolov8l", "yolov10n", "yolov10s", "yolov10m", "yolov10l"], help="One or more models to use for the experiments.")
|
| 37 |
+
parser.add_argument("--epochs", type=int, default=1000, help="Number of epochs.")
|
| 38 |
+
parser.add_argument("--batch", type=int, default=16, help="Batch size.")
|
| 39 |
+
parser.add_argument("--plots", action="store_true", default=True, help="Generate plots for all runs.")
|
| 40 |
+
|
| 41 |
+
args = parser.parse_args()
|
| 42 |
+
|
| 43 |
+
# Define the sequence of experiments to run for each model
|
| 44 |
+
# Each tuple is (run_mode, use_pretrained_flag)
|
| 45 |
+
experiment_sequence = [
|
| 46 |
+
("From_Scratch", False),
|
| 47 |
+
("Finetuning", True),
|
| 48 |
+
("freeze_[P1-P3]", True),
|
| 49 |
+
("freeze_Backbone", True),
|
| 50 |
+
("freeze_[P1-23]", True)
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
# Iterate over each specified model variant
|
| 54 |
+
for model_name in args.model:
|
| 55 |
+
print(f"\n{'='*25} Starting Experiments for Model: {model_name.upper()} {'='*25}\n")
|
| 56 |
+
|
| 57 |
+
# Base command list, specific to the current model
|
| 58 |
+
base_command = [
|
| 59 |
+
"python", "main.py",
|
| 60 |
+
"--dataset", args.dataset,
|
| 61 |
+
"--epochs", str(args.epochs),
|
| 62 |
+
"--batch", str(args.batch),
|
| 63 |
+
"--model", model_name
|
| 64 |
+
]
|
| 65 |
+
if args.plots:
|
| 66 |
+
base_command.append("--plots")
|
| 67 |
+
|
| 68 |
+
# Execute each experiment in sequence for the current model
|
| 69 |
+
for run_mode, use_pretrained in experiment_sequence:
|
| 70 |
+
run_experiment(base_command, run_mode, use_pretrained)
|
| 71 |
+
|
| 72 |
+
print("="*80)
|
| 73 |
+
print("All experiments for all specified models have been completed.")
|
| 74 |
+
print("="*80)
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
main()
|