-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeature_Grid_Inference.py
More file actions
51 lines (36 loc) · 1.94 KB
/
Copy pathFeature_Grid_Inference.py
File metadata and controls
51 lines (36 loc) · 1.94 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
51
import numpy as np
import torch
from model.model_utils import setup_model, restore_model
from visualization.pltUtils import dict_from_file
from visualization.OutputToVTK import tiled_net_out
from data.IndexDataset import get_tensor, IndexDataset
def infer_model(model, dataset, volume):
psnr, l1_diff, mse, rmse = tiled_net_out(dataset, model, True, gt_vol=volume.cpu(), evaluate=True, write_vols=True)
pass
def create_model_from_checkpoint(args):
model = setup_model(args['d_in'], args['n_hidden_size'], args['d_out'], args['n_layers'], args['embedding_type'],
args['n_embedding_freq'], '', args['drop_momentum'], args['drop_threshold'],
args['wavelet_filter'], args['grid_features'], args['grid_size'], args['checkpoint_path'])
return model
def create_model_from_binary_file(args):
model = restore_model(args['binary_checkpoint_path'])
return model
if __name__ == '__main__':
import configargparse
parser = configargparse.ArgumentParser()
parser.add_argument("--config_path", type=str, required=True,
help='path to config of model; is required')
parser.add_argument("--reconstruct", type=str, required=True,
help='from where to reconstruct the model from: binary: from binary files;'
' checkpoint: from model checkpoint')
args = vars(parser.parse_args())
config = dict_from_file(args['config_path'])
volume = get_tensor(config['data'])
dataset = IndexDataset(volume, config['sample_size'])
if args['reconstruct'] == 'checkpoint':
model = create_model_from_checkpoint(config)
if args['reconstruct'] == 'binary':
model = create_model_from_binary_file(config)
if args['reconstruct'] != 'binary' and args['reconstruct'] != 'checkpoint':
print("Wrong --reconstruct parameter! Specify either 'binary' or 'checkpoint'")
infer_model(model, dataset, volume)