MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / train_feature

Function train_feature

script/run_feature.py:232–422  ·  view source on GitHub ↗
(args, train_dl, val_dl, test_dl, hwf, i_split, near, far)

Source from the content-addressed store, hash-verified

230 return train_loss
231
232def train_feature(args, train_dl, val_dl, test_dl, hwf, i_split, near, far):
233
234 # # load pretrained PoseNet model
235 if args.DFNet_s:
236 feat_model = DFNet_s()
237 else:
238 feat_model = DFNet()
239
240 if args.pretrain_model_path != '':
241 print("load posenet from ", args.pretrain_model_path)
242 feat_model.load_state_dict(torch.load(args.pretrain_model_path))
243
244 # # Freeze BN to not updating gamma and beta
245 if args.freezeBN:
246 feat_model = freeze_bn_layer(feat_model)
247
248 feat_model.to(device)
249 # summary(feat_model, (3, 240, 427))
250
251 # set optimizer
252 optimizer = optim.Adam(feat_model.parameters(), lr=args.learning_rate)
253 scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, factor=0.95, patience=args.patience[1], verbose=True)
254
255 # set callbacks parameters
256 early_stopping = EarlyStopping(args, patience=args.patience[0], verbose=False)
257
258 # loss function
259 loss_func = nn.MSELoss(reduction='mean')
260
261 i_train, i_val, i_test = i_split
262 # Cast intrinsics to right types
263 H, W, focal = hwf
264 H, W = int(H), int(W)
265 hwf = [H, W, focal]
266
267 # Create log dir and copy the config file
268 basedir = args.basedir
269 expname = args.expname
270 os.makedirs(os.path.join(basedir, expname), exist_ok=True)
271 f = os.path.join(basedir, expname, 'args.txt')
272 with open(f, 'w') as file:
273 for arg in sorted(vars(args)):
274 attr = getattr(args, arg)
275 file.write('{} = {}\n'.format(arg, attr))
276 if args.config is not None:
277 f = os.path.join(basedir, expname, 'config.txt')
278 with open(f, 'w') as file:
279 file.write(open(args.config, 'r').read())
280
281 # load NeRF
282 _, render_kwargs_test, start, _, _ = create_nerf(args)
283 global_step = start
284
285 bds_dict = {
286 'near' : near,
287 'far' : far,
288 }
289 # render_kwargs_train.update(bds_dict)

Callers 1

trainFunction · 0.85

Calls 12

DFNet_sClass · 0.90
DFNetClass · 0.90
freeze_bn_layerFunction · 0.90
EarlyStoppingClass · 0.90
create_nerfFunction · 0.90
render_nerfw_imgsFunction · 0.85
render_virtual_imgsFunction · 0.85
train_on_batchFunction · 0.70
get_error_in_qFunction · 0.50

Tested by

no test coverage detected