-
Notifications
You must be signed in to change notification settings - Fork 5
/
lp_feat_extractor.py
75 lines (57 loc) · 2.21 KB
/
lp_feat_extractor.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
import os
import numpy as np
import torch
from utils.utils import get_dataset, init_distributed_mode, set_random_seed, copy_log_from_pueue
from utils.tokenizer import SimpleTokenizer
from data.dataset_3d import *
import models.ULIP_models as models
def main(args):
init_distributed_mode(args)
if args.seed >= 0:
seed = args.seed
set_random_seed(seed)
print("Setting fixed seed: {}".format(seed))
if torch.cuda.is_available():
torch.backends.cudnn.benchmark = True
######################################
# Setup DataLoader
######################################
tokenizer = SimpleTokenizer()
if args.dataset_type == 'train':
dataset = get_dataset(None, tokenizer, args, 'train')
shuffle = True
print('------ len(train_dataset)', len(dataset))
else:
dataset = get_dataset(None, tokenizer, args, 'test')
shuffle = False
print('------ len(val_dataset)', len(dataset))
data_loader = torch.utils.data.DataLoader(
dataset, batch_size=args.batch_size, shuffle=shuffle,
num_workers=args.workers, pin_memory=True, drop_last=False)
########################################
# Setup Network
########################################
model = getattr(models, args.model)(args)
point_encoder = model.point_encoder.to(args.gpu)
point_encoder.eval()
###################################################################################################################
# Start Feature Extractor
feature_list = []
label_list = []
for _, inputs in enumerate(data_loader):
pc = inputs[0].to(args.gpu)
feature = point_encoder(pc)
feature = feature.cpu()
for idx in range(len(pc)):
feature_list.append(feature[idx].tolist())
label_list.extend(inputs[1].tolist())
save_dir = os.path.join(args.output_dir, args.proj_name, args.exp_name)
np.savez(
os.path.join(save_dir, args.dataset_type),
feature_list=feature_list,
label_list=label_list,
)
copy_log_from_pueue(args.output_dir, args.proj_name, args.exp_name, 'run.log')
if __name__ == "__main__":
from parser import args
main(args)