-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
95 lines (80 loc) · 3.03 KB
/
Copy pathmain.py
File metadata and controls
95 lines (80 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
DEVICE_IDS = 0 # modify this to run on a different GPU id.
os.environ["CUDA_VISIBLE_DEVICES"] = str(DEVICE_IDS)
from config import *
from data_utils import *
from train_utils import *
from utils import *
from models import *
import numpy as np
import warnings
warnings.filterwarnings('ignore')
if __name__ == '__main__':
DEVICE_ID = DEVICE_IDS
MONITOR_WANDB = True
SCALE_FACTOR = 1/4
IMAGE_SIZE = int(SCALE_FACTOR * 512)
BATCH_SIZE = 70
EXPERIMENT = "experiment_name"
SAVE_MODELS = False
NUM_EXPERIMENTS = 5
RUN_NAME = f'{DEVICE_ID}-{IMAGE_SIZE}-{BATCH_SIZE}-resnet50-baseline-datetime_{date_time}'
if SAVE_MODELS:
os.makedirs(MODEL_SAVE_DIR,exist_ok=True)
if MONITOR_WANDB:
run = wandb.init(project=EXPERIMENT, entity="your_name", reinit=True)
wandb.run.name = RUN_NAME
wandb.run.save()
train_dataset,val_dataset = get_train_val_dataset(TRAIN_CSV_PATH,
TRAIN_CSV_PATH,
SANITY_CHECK,
SANITY_DATA_LEN,
TRAIN_ROOT_DIR,
VAL_ROOT_DIR,
IMAGE_SIZE,
MEAN,
STD,
dataset_name='pandas')
best_accuracies = []
best_metrics = []
seeds = np.random.randint(10,10000,NUM_EXPERIMENTS)
for run_number, seed in enumerate([42]):
print(f"Run Number:{run_number}, seed:{seed}")
if MONITOR_WANDB:
wandb.log({
'run_number': run_number,
'seed': seed,
})
trainer = Trainer(seed,
run_number,
train_dataset,
val_dataset,
BATCH_SIZE,
NUM_WORKERS,
NUM_CLASSES,
ACCELARATOR,
RUN_NAME,
LEARNING_RATE,
EPOCHS,
WARMUP_EPOCHS,
DECAY_FACTOR,
MONITOR_WANDB,
SAVE_MODELS,
MODEL_SAVE_DIR)
logs = trainer.run()
best_accuracies.append(logs['best_accuracy'])
best_metrics.append(logs['best_metric'])
del trainer
if MONITOR_WANDB:
print({
'mean_accuracies': np.mean(best_accuracies),
'std_accuracies': np.std(best_accuracies),
'mean_kappa': np.mean(best_metrics),
'std_kappa': np.std(best_metrics),
})
wandb.log({
'mean_accuracies': np.mean(best_accuracies),
'std_accuracies': np.std(best_accuracies),
'mean_kappa': np.mean(best_metrics),
'std_kappa': np.std(best_metrics),
})