-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (35 loc) · 1.4 KB
/
Copy pathmain.py
File metadata and controls
50 lines (35 loc) · 1.4 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
import torch
import higher
import torchmeta
import os
from torchmeta.datasets.helpers import miniimagenet
from torchmeta.utils.data import BatchMetaDataLoader
from time import time
from models.metaconv import MetaConv
from models.metaconv_contextual import MetaConvContextual
from learners.meta_trainer import MetaTrainer
def start_experiment():
# Setting benchmark = True should improve performance for constant shape input
# torch.backends.cudnn.benchmark = True
meta_trainer = MetaTrainer()
if meta_trainer.args.test_only:
print("Skipping training.")
# Reinitialize with given seed to make testing deterministic
meta_trainer = MetaTrainer(test_seed=42)
checkpoint_name = meta_trainer.args.checkpoint_name if meta_trainer.args.checkpoint_name else "best_checkpoint"
meta_trainer.test(checkpoint=checkpoint_name)
else:
meta_trainer.train(training=True, checkpoint=meta_trainer.args.checkpoint_name)
# Test using best checkpoint saved
meta_trainer = MetaTrainer(test_seed=42)
meta_trainer.test(checkpoint="best_checkpoint")
# Close summary writer
meta_trainer.writer.close()
def main():
# Set working directory to parent directory
os.chdir(os.path.dirname(os.path.abspath(__file__)))
print(torch.cuda.is_available())
print(torchmeta.__version__)
start_experiment()
if __name__ == '__main__':
main()