text stringlengths 1 93.6k |
|---|
model_name = os.path.join(
|
args.res_dir, 'run{}_model_checkpoint{}.pth'.format(run+1, epoch))
|
optimizer_name = os.path.join(
|
args.res_dir, 'run{}_optimizer_checkpoint{}.pth'.format(run+1, epoch))
|
torch.save(model.state_dict(), model_name)
|
torch.save(optimizer.state_dict(), optimizer_name)
|
final_res = '''Run {}\nBest validation score: {}\nTest score: {}
|
'''.format(run+1, best_valid_perf, best_test_perf)
|
print('Finished training!')
|
cmd_input = 'python ' + ' '.join(sys.argv)
|
print(cmd_input)
|
print(final_res)
|
with open(log_file, 'a') as f:
|
print(final_res, file=f)
|
if args.ensemble:
|
print('Start ensemble testing...')
|
start_epoch, end_epoch = args.epochs - args.ensemble_lookback, args.epochs
|
checkpoints = [
|
os.path.join(args.res_dir, 'run{}_model_checkpoint{}.pth'.format(run+1, x))
|
for x in range(start_epoch, end_epoch+1, args.ensemble_interval)
|
]
|
ensemble_valid_perf = eval(model, device, valid_loader, evaluator, False,
|
dataset.task_type, checkpoints)[eval_metric]
|
ensemble_test_perf = eval(model, device, test_loader, evaluator, False,
|
dataset.task_type, checkpoints)[eval_metric]
|
ensemble_res = '''Run {}\nEnsemble validation score: {}\nEnsemble test score: {}
|
'''.format(run+1, ensemble_valid_perf, ensemble_test_perf)
|
cmd_input = 'python ' + ' '.join(sys.argv)
|
print(cmd_input)
|
print(ensemble_res)
|
with open(log_file, 'a') as f:
|
print(ensemble_res, file=f)
|
if args.ensemble:
|
valid_perfs.append(ensemble_valid_perf)
|
test_perfs.append(ensemble_test_perf)
|
else:
|
valid_perfs.append(best_valid_perf)
|
test_perfs.append(best_test_perf)
|
valid_perfs = torch.tensor(valid_perfs)
|
test_perfs = torch.tensor(test_perfs)
|
print('===========================')
|
print(cmd_input)
|
print(f'Final Valid: {valid_perfs.mean():.4f} ± {valid_perfs.std():.4f}')
|
print(f'Final Test: {test_perfs.mean():.4f} ± {test_perfs.std():.4f}')
|
print(valid_perfs.tolist())
|
print(test_perfs.tolist())
|
# <FILESEP>
|
# Future
|
from __future__ import print_function
|
# Built-in module
|
import argparse
|
import warnings
|
warnings.filterwarnings(action='ignore')
|
# torch pkg
|
import torch
|
import torch.optim as optim
|
import torch.distributed as dist
|
# Cudnn settings
|
torch.backends.cudnn.benchmark = True
|
torch.autograd.profiler.emit_nvtx(False)
|
torch.autograd.profiler.profile(False)
|
# Import Custom Utils
|
from utils.fast_network_utils import get_network
|
from utils.fast_data_utils import get_fast_dataloader
|
from utils.utils import *
|
from utils.scheduler import WarmupCosineSchedule
|
# Accelerating forward and backward
|
from torch.cuda.amp import GradScaler, autocast
|
# fetch args
|
parser = argparse.ArgumentParser()
|
# model parameter
|
parser.add_argument('--NAME', default='STANDARD', type=str)
|
parser.add_argument('--dataset', default='cifar10', type=str)
|
parser.add_argument('--network', default='vgg', type=str)
|
parser.add_argument('--depth', default=16, type=int, help='cait depth = 24')
|
parser.add_argument('--gpu', default='0,1,2,3', type=str)
|
parser.add_argument('--port', default="12000", type=str)
|
# transformer parameter
|
parser.add_argument('--tran_type', default='small', type=str, help='small/base')
|
parser.add_argument('--img_resize', default=224, type=int, help='224')
|
parser.add_argument('--patch_size', default=16, type=int, help='16')
|
parser.add_argument('--warmup-steps', default=500, type=int)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.