-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_modelnet_3D.py
155 lines (138 loc) · 5.83 KB
/
test_modelnet_3D.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
import numpy as np
import time, sys, os, cv2
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# 0 = all messages are logged(default behavior)
# 1 = INFO messages are not printed
# 2 = INFO and WARNING messages arenot printed
# 3 = INFO, WARNING, and ERROR messages arenot printed
import src.dataset_loader.KITTI_dataset as KITTI
from src.dataset_loader.modelnet_dataset import dataLoader
import src.net_core.darknet as Darknet
import src.module.nolbo as nolbo
import tensorflow as tf
tf.get_logger().warning('test')
# WARNING:tensorflow:test
tf.get_logger().setLevel('ERROR')
tf.get_logger().warning('test')
latent_dim = 64
config = {
'z_category_dim': latent_dim,
'encoder': {
'name':'encoder3D',
'input_shape': [64,64,64,1], # or [None,None,None,1]
'filter_num_list': [64,128,256,512, 2 * latent_dim],
'filter_size_list': [4,4,4,4,4],
'strides_list': [2,2,2,2,1],
'final_pool': 'average',
'activation': 'elu',
'final_activation': 'None',
},
'decoder':{
'name':'decoder',
'input_dim': latent_dim,
'output_shape': [64,64,64,1],
'filter_num_list': [512,256,128,64,1],
'filter_size_list': [4,4,4,4,4],
'strides_list': [1,2,2,2,2],
'activation': 'elu',
'final_activation': 'sigmoid'
},
'prior_class': {
'name': 'priornet_class',
'input_dim': 40, # class num (one-hot vector)
'unit_num_list': [32, latent_dim],
'core_activation': 'elu',
'const_log_var': 0.0,
},
}
config_AE = {
'z_category_dim': latent_dim,
'encoder': {
'name':'encoder3D',
'input_shape': [64,64,64,1], # or [None,None,None,1]
'filter_num_list': [64,128,256,512, latent_dim],
'filter_size_list': [4,4,4,4,4],
'strides_list': [2,2,2,2,1],
'final_pool': 'average',
'activation': 'elu',
'final_activation': 'None',
},
'decoder':{
'name':'decoder',
'input_dim': latent_dim,
'output_shape': [64,64,64,1],
'filter_num_list': [512,256,128,64,1],
'filter_size_list': [4,4,4,4,4],
'strides_list': [1,2,2,2,2],
'activation': 'elu',
'final_activation': 'sigmoid'
},
}
config_VAE = {
'z_category_dim': latent_dim,
'encoder': {
'name':'encoder3D',
'input_shape': [64,64,64,1], # or [None,None,None,1]
'filter_num_list': [64,128,256,512, 2 * latent_dim],
'filter_size_list': [4,4,4,4,4],
'strides_list': [2,2,2,2,1],
'final_pool': 'average',
'activation': 'elu',
'final_activation': 'None',
},
'decoder':{
'name':'decoder',
'input_dim': latent_dim,
'output_shape': [64,64,64,1],
'filter_num_list': [512,256,128,64,1],
'filter_size_list': [4,4,4,4,4],
'strides_list': [1,2,2,2,2],
'activation': 'elu',
'final_activation': 'sigmoid'
},
}
def test(
dataset_path=None,
batch_size=72,
save_dir='./data/eval/image/modelnet/'
):
model = nolbo.nolboSingleObject_modelnet_category_only(nolbo_structure=config)
model_AE = nolbo.nolboSingleObject_modelnet_category_AE(nolbo_structure=config_AE)
model_VAE = nolbo.nolboSingleObject_modelnet_category_VAE(nolbo_structure=config_VAE)
data_loader_test = dataLoader(data_path=dataset_path, trainortest='test')
batch_data = data_loader_test.getNextBatch(batchSize=batch_size)
inst_list, category_list, input_images, output_images = batch_data['inst_list'], batch_data['class_list'], \
batch_data['input_images'], batch_data['input_images']
data = input_images, output_images, category_list
for missing_pr in [0.30, 0.50, 0.70, 0.90]:
print(missing_pr)
model.loadModel('./weights/modelnet_category/')
model_AE.loadModel('./weights/modelnet_category_AE')
model_VAE.loadModel('./weights/modelnet_category_VAE')
input_images, output_images = data[0], data[1]
output_images_pred, _, _, _, _, output_images_pred_corrected, _, _, _, _ = model.getEval(inputs=data, missing_prob=missing_pr)
output_images_pred_AE, _, _, _ = model_AE.getEval(inputs=data[0:2], missing_prob=missing_pr)
output_images_pred_VAE, _, _, _ = model_VAE.getEval(inputs=data[0:2], missing_prob=missing_pr)
i = 0
for input_image, output_image_gt, output_image_mVAE, output_image_mVAE_corrected, output_image_AE, output_image_VAE in zip(
input_images, output_images, output_images_pred, output_images_pred_corrected, output_images_pred_AE, output_images_pred_VAE
):
file_name = '{:03d}'.format(int(i))
output_image_gt = np.reshape(output_image_gt, (64*64, 64))
np.savetxt(os.path.join(save_dir, file_name+'_'+str(missing_pr)+'_gt.txt'), output_image_gt)
output_image_mVAE = np.reshape(output_image_mVAE, (64 * 64, 64))
np.savetxt(os.path.join(save_dir, file_name+'_'+str(missing_pr)+'_ca.txt'), output_image_mVAE)
output_image_mVAE_corrected = np.reshape(output_image_mVAE_corrected, (64 * 64, 64))
np.savetxt(os.path.join(save_dir, file_name+'_'+str(missing_pr)+'_ca_corrected.txt'), output_image_mVAE_corrected)
output_image_AE = np.reshape(output_image_AE, (64 * 64, 64))
np.savetxt(os.path.join(save_dir, file_name+'_'+str(missing_pr)+'_AE.txt'), output_image_AE)
output_image_VAE = np.reshape(output_image_VAE, (64 * 64, 64))
np.savetxt(os.path.join(save_dir, file_name+'_'+str(missing_pr)+'_VAE.txt'), output_image_VAE)
i += 1
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
if __name__ == '__main__':
sys.exit(test(
dataset_path='/media/yonsei/4TB_HDD/dataset/modelNet/',
batch_size=128,
save_dir='./data/eval/image/modelnet/'
))