forked from SamitHuang/EV_GCN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opt.py
63 lines (52 loc) · 2.42 KB
/
opt.py
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
import os
import datetime
import argparse
import random
import numpy as np
import torch
import logging
import logging.config
class OptInit():
def __init__(self):
parser = argparse.ArgumentParser(description='PyTorch implementation of EV-GCN')
parser.add_argument('--train', default=1, type=int, help='train(default) or evaluate')
parser.add_argument('--use_cpu', action='store_true', help='use cpu?')
parser.add_argument('--hgc', type=int, default=16, help='hidden units of gconv layer')
parser.add_argument('--lg', type=int, default=4, help='number of gconv layers')
parser.add_argument('--lr', default=0.01, type=float, help='initial learning rate')
parser.add_argument('--wd', default=5e-5, type=float, help='weight decay')
parser.add_argument('--num_iter', default=300, type=int, help='number of epochs for training')
parser.add_argument('--edropout', type=float, default=0.3, help='edge dropout rate')
parser.add_argument('--dropout', default=0.2, type=float, help='ratio of dropout')
parser.add_argument('--num_classes', type=int, default=2, help='number of classes')
parser.add_argument('--ckpt_path', type=str, default='./save_models/ev_gcn', help='checkpoint path to save trained models')
args = parser.parse_args()
args.time = datetime.datetime.now().strftime("%y%m%d")
if args.use_cpu:
args.device = torch.device('cpu')
else:
args.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(" Using GPU in torch")
self.args = args
def print_args(self):
# self.args.printer args
print("========== CONFIG =============")
for arg, content in self.args.__dict__.items():
print("{}:{}".format(arg, content))
print("========== CONFIG END =============")
print("\n")
phase = 'train' if self.args.train==1 else 'eval'
print('===> Phase is {}.'.format(phase))
def initialize(self):
self.set_seed(123)
#self.logging_init()
self.print_args()
return self.args
def set_seed(self, seed=0):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False