-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.py
191 lines (155 loc) · 5.15 KB
/
config.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# encoding=utf8
# ////////////////////////////////////////////////////////////////////////////
# // This file is part of NIID-Net. For more information
# // see <https://github.com/zju3dv/NIID-Net>.
# // If you use this code, please cite the corresponding publications as
# // listed on the above website.
# //
# // Copyright (c) ZJU-SenseTime Joint Lab of 3D Vision. All Rights Reserved.
# //
# // Permission to use, copy, modify and distribute this software and its
# // documentation for educational, research and non-profit purposes only.
# //
# // The above copyright notice and this permission notice shall be included in all
# // copies or substantial portions of the Software.
# //
# // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# // SOFTWARE.
# ////////////////////////////////////////////////////////////////////////////
import os
import warnings
import torch
class CriteriaTypes(object):
normal = 0
warm_up = 1
shading_warm_up = 2
shading = 3
reflectance = 4
IID = 5
@classmethod
def is_valid(cls, label):
return label in [cls.normal, cls.warm_up, cls.shading_warm_up, cls.shading, cls.reflectance, cls.IID]
@classmethod
def train_shading(cls, label):
return label in [cls.warm_up, cls.shading_warm_up, cls.shading, cls.IID]
@classmethod
def train_reflectance(cls, label):
return label in [cls.warm_up, cls.reflectance, cls.IID]
@classmethod
def train_surface_normal(cls, label):
return label in [cls.normal]
@classmethod
def warm_up_shading(cls, label):
return label in [cls.warm_up, cls.shading_warm_up]
class DefaultConfig(object):
# Checkpoints dir (default)
checkpoints_dir = './checkpoints/'
# Visdom
env = 'default'
server = 'http://localhost'
port = 18097
offline = True
# Dataset Path Config
dataset_root = './dataset/'
DIODE_root = os.path.join(dataset_root, 'DIODE/')
NYUv2_root = os.path.join(dataset_root, 'nyu_depth_v2_large/')
CGI_root = os.path.join(dataset_root, 'CGIntrinsics/')
diode_meta_fname = os.path.join(DIODE_root, 'diode_meta.json')
# Input
normal_input_size = (240, 320)
batch_size_normal = 1
num_workers_normal = 1
batch_size_intrinsics = 1
batch_size_iiw = 1
batch_size_saw = 1
num_workers_intrinsics = 1
num_workers_Render = 1
# Model
model = 'NIID-Net'
pretrained_file = './pretrained_model/final.pth.tar'
load_pretrained_NEM = False
load_pretrained_IID_Net = False
# State
isTrain = False
# GPU
use_gpu = True
gpu_devices = [0]
# Parse
def parse(self, kwargs):
""" Update configuration according to kwargs
"""
print('\nUpdate config:')
for k, v in kwargs.items():
# GPU NUM
if k == 'gpu_num':
self.gpu_devices = [n + torch.cuda.current_device() for n in range(int(v))]
print(' gpu_devices: %s' % self.gpu_devices)
continue
if not hasattr(self, k):
warnings.warn("Warning: opt has not attribut %s" % k)
setattr(self, k, v)
print(' %s: %s' % (k, v))
# print('user config:')
# for k, v in self.__class__.__dict__.items():
# if not k.startswith('__'):
# print(k, getattr(self, k))
print('\n')
class TestOptions(DefaultConfig):
# State
isTrain = False
# Pretrained
load_pretrained_NEM = True
load_pretrained_IID_Net = True
# Visualization
env = 'NIID-Net_test' # visdom environment
class TrainIIDOptions(DefaultConfig):
# Pretrained
load_pretrained_NEM = True
load_pretrained_IID_Net = False
# Train
isTrain = True
train_epoch = 50
iter_each_epoch = None
criteria = None
# Optimizer
use_SGD = False
lr = 1e-4 # default learning rate
weight_decay = 0e-4
optim_NEM = False
optim_IID = 'wo_R' # None, 'full', 'wo_R' (train without the R decoder), 'R' (only R decoder)
# Scheduler
scheduler_type = 'plateau'
scheduler_mode = 'max'
lr_decay = 0.5
sd_patience = 5
min_lr = 1e-6
# Visualization
env = 'NIID-Net_train_IIDNet'
class TrainNormalOptions(DefaultConfig):
# Pretrained
load_pretrained_NEM = True
load_pretrained_IID_Net = False
# Train
isTrain = True
train_epoch = 50
iter_each_epoch = None
criteria = CriteriaTypes.normal
# Optimizer
use_SGD = False
lr = 5e-5 # default learning rate
weight_decay = 1e-4
optim_NEM = True
optim_IID = None
# Scheduler
scheduler_type = 'plateau'
scheduler_mode = 'max'
lr_decay = 0.5
sd_patience = 5
min_lr = 1e-8
# Visualization
env = 'NIID-Net_train_NEM'