MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / train

Function train

script/train.py:95–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93 return
94
95def train():
96 print(parser.format_values())
97 # Load data
98 if args.dataset_type == '7Scenes':
99 train_dl, val_dl, test_dl, hwf, i_split, near, far = load_7Scenes_dataloader(args)
100 elif args.dataset_type == 'Cambridge':
101 train_dl, val_dl, test_dl, hwf, i_split, near, far = load_Cambridge_dataloader(args)
102 else:
103 print("please choose dataset_type: 7Scenes or Cambridge, exiting...")
104 sys.exit()
105
106 ### pose regression module, here requires a pretrained DFNet for Pose Estimator F
107 assert(args.pretrain_model_path != '') # make sure to add a valid PATH using --pretrain_model_path
108 # load pretrained DFNet model
109 model = load_exisiting_model(args)
110
111 if args.freezeBN:
112 model = freeze_bn_layer(model)
113 model.to(device)
114
115 ### feature extraction module, here requires a pretrained DFNet for Feature Extractor G using --pretrain_featurenet_path
116 if args.pretrain_featurenet_path == '':
117 print('Use the same DFNet for Feature Extraction and Pose Regression')
118 feat_model = load_exisiting_model(args)
119 else:
120 # you can optionally load different pretrained DFNet for feature extractor and pose estimator
121 feat_model = load_exisiting_model(args, isFeatureNet=True)
122
123 feat_model.eval()
124 feat_model.to(device)
125
126 # set optimizer
127 optimizer = optim.Adam(model.parameters(), lr=args.learning_rate) #weight_decay=weight_decay, **kwargs
128
129 # set callbacks parameters
130 early_stopping = EarlyStopping(args, patience=args.patience[0], verbose=False)
131
132 # start training
133 if args.dataset_type == '7Scenes':
134 train_feature_matching(args, model, feat_model, optimizer, i_split, hwf, near, far, device, early_stopping, train_dl=train_dl, val_dl=val_dl, test_dl=test_dl)
135 elif args.dataset_type == 'Cambridge':
136 train_feature_matching(args, model, feat_model, optimizer, i_split, hwf, near, far, device, early_stopping, train_dl=train_dl, val_dl=val_dl, test_dl=test_dl)
137
138def eval():
139 print(parser.format_values())

Callers 1

train.pyFile · 0.70

Calls 6

load_7Scenes_dataloaderFunction · 0.90
freeze_bn_layerFunction · 0.90
EarlyStoppingClass · 0.90
train_feature_matchingFunction · 0.90
load_exisiting_modelFunction · 0.85

Tested by

no test coverage detected