forked from tinghuiz/SfMLearner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSfMLearner.py
46 lines (39 loc) · 1.57 KB
/
SfMLearner.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
from __future__ import division
import tensorflow as tf
from nets import *
class SfMLearner(object):
def __init__(self,
batch_size=4,
img_height=128,
img_width=416):
self.batch_size = batch_size
self.img_height = img_height
self.img_width = img_width
def build_depth_test_graph(self):
input_uint8 = tf.placeholder(tf.uint8, [self.batch_size,
self.img_height, self.img_width, 3], name='raw_input')
input_mc = self.preprocess_image(input_uint8)
with tf.name_scope("depth_prediction"):
pred_disp, depth_net_endpoints = disp_net(input_mc)
pred_depth = [1./disp for disp in pred_disp]
pred_depth = pred_depth[0]
self.inputs = input_uint8
self.pred_depth = pred_depth
self.depth_epts = depth_net_endpoints
def preprocess_image(self, image):
# Assuming input image is uint8
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
return image * 2. -1.
def deprocess_image(self, image):
# Assuming input image is float32
image = (image + 1.)/2.
return tf.image.convert_image_dtype(image, dtype=tf.uint8)
def setup_inference_graph(self, mode='depth'):
if mode == 'depth':
self.build_depth_test_graph()
def inference(self, inputs, sess, mode='depth'):
fetches = {}
if mode == 'depth':
fetches['depth'] = self.pred_depth
results = sess.run(fetches, feed_dict={self.inputs:inputs})
return results