-
Notifications
You must be signed in to change notification settings - Fork 182
/
geonet_test_depth.py
54 lines (46 loc) · 1.94 KB
/
geonet_test_depth.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
from __future__ import division
import tensorflow as tf
import numpy as np
import os
import PIL.Image as pil
from geonet_model import *
def test_depth(opt):
##### load testing list #####
with open('data/kitti/test_files_%s.txt' % opt.depth_test_split, 'r') as f:
test_files = f.readlines()
test_files = [opt.dataset_dir + t[:-1] for t in test_files]
if not os.path.exists(opt.output_dir):
os.makedirs(opt.output_dir)
##### init #####
input_uint8 = tf.placeholder(tf.uint8, [opt.batch_size,
opt.img_height, opt.img_width, 3], name='raw_input')
model = GeoNetModel(opt, input_uint8, None, None)
fetches = { "depth": model.pred_depth[0] }
saver = tf.train.Saver([var for var in tf.model_variables()])
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
##### Go #####
with tf.Session(config=config) as sess:
saver.restore(sess, opt.init_ckpt_file)
pred_all = []
for t in range(0, len(test_files), opt.batch_size):
if t % 100 == 0:
print('processing: %d/%d' % (t, len(test_files)))
inputs = np.zeros(
(opt.batch_size, opt.img_height, opt.img_width, 3),
dtype=np.uint8)
for b in range(opt.batch_size):
idx = t + b
if idx >= len(test_files):
break
fh = open(test_files[idx], 'r')
raw_im = pil.open(fh)
scaled_im = raw_im.resize((opt.img_width, opt.img_height), pil.ANTIALIAS)
inputs[b] = np.array(scaled_im)
pred = sess.run(fetches, feed_dict={input_uint8: inputs})
for b in range(opt.batch_size):
idx = t + b
if idx >= len(test_files):
break
pred_all.append(pred['depth'][b,:,:,0])
np.save(opt.output_dir + '/' + os.path.basename(opt.init_ckpt_file), pred_all)