Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/iitmcvg/CNN_SLAM
Browse files Browse the repository at this point in the history
  • Loading branch information
varun19299 committed Nov 2, 2018
2 parents 9e0bdae + 80a48d3 commit f03d5c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion monodepth/monodepth_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class MonodepthModel(object):
"""monodepth model"""

def __init__(self, params, mode, left, right, reuse_variables=None, model_index=0):
def __init__(self, params, mode, left, right, reuse_variables=tf.AUTO_REUSE, model_index=0):
self.params = params
self.mode = mode
self.left = left
Expand Down
27 changes: 21 additions & 6 deletions monodepth_infer/monodepth_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tensorflow.contrib.slim as slim
import tensorflow as tf
import numpy as np

import cv2

# Module imports
import monodepth.average_gradients as average_gradients
Expand Down Expand Up @@ -46,7 +46,21 @@ def init_monodepth(checkpoint_path, sess = None):
# SESSION
if not sess:
left = tf.placeholder(tf.float32, [2, input_height, input_width, 3])
model = MonodepthModel(params, "test", left, None)
params = monodepth_model.monodepth_parameters(
encoder="resnet50",
height=input_height,
width=input_width,
batch_size=2,
num_threads=1,
num_epochs=1,
do_stereo=False,
wrap_mode="border",
use_deconv=False,
alpha_image_loss=0,
disp_gradient_loss_weight=0,
lr_loss_weight=0,
full_summary=False)
model = monodepth_model.MonodepthModel(params, "test", left, None)
config = tf.ConfigProto(allow_soft_placement=True)
sess = tf.Session(config=config)

Expand Down Expand Up @@ -81,7 +95,8 @@ def get_depth_map(sess, image_array, encoder="resnet50"):
* Use frozen graphs instead
* Switch to tf.data.Datasets
'''
input_height, input_width = image_array.shape()[:2]
# org_input_height, org_input_width = image_array.shape[:2]

params = monodepth_model.monodepth_parameters(
encoder=encoder,
height=input_height,
Expand All @@ -102,14 +117,14 @@ def get_depth_map(sess, image_array, encoder="resnet50"):

input_image = image_array
original_height, original_width, num_channels = input_image.shape
input_image = cv2.resize(input_image,(input_width, input_height),interpolation = cv2.INTER_CUBIC)
input_image = input_image.astype(np.float32) / 255
input_images = np.stack((input_image, np.fliplr(input_image)), 0)

disp = sess.run(model.disp_left_est[0], feed_dict={left: input_images})
disp_pp = post_process_disparity(disp.squeeze()).astype(np.float32)

disp_to_img = scipy.misc.imresize(
disp_pp.squeeze(), [
original_height, original_width])
disp_to_img = cv2.resize(
disp_pp.squeeze(), (original_height, original_width))

return disp_to_img
12 changes: 6 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import pose_estimation.camera_pose_estimation as camera_pose_estimation
import pose_estimation.find_uncertainty as find_uncertainty"""
from keyframe_utils import Keyframe as Keyframe
import monodepth_infer.monodepth_single as monodepth
import monodepth_infer.monodepth_single as monodepth_single

parser = argparse.ArgumentParser(description='Monodepth TensorFlow implementation.')
parser.add_argument('--mono_checkpoint_path', default = "checkpoints/model_kitti_resnet/model_kitti_resnet.data" ,type=str, help='path to a specific checkpoint to load')
Expand Down Expand Up @@ -84,8 +84,8 @@ def _exit_program():
raise NotImplementedError

def main():
# INIT monodepth session
sess=monodepth.init_monodepth(args.mono_checkpoint_path)
# INIT monodepth_single session
sess=monodepth_single.init_monodepth(args.mono_checkpoint_path)

# INIT camera matrix
cam_matrix = get_camera_matrix()
Expand All @@ -103,7 +103,7 @@ def main():

# Predict depth
image = cv2.imread("pose_estimation/stereo.jpeg")
ini_depth = monodepth.get_cnn_depth(sess,image)
ini_depth = monodepth_single.get_depth_map(sess,image)
cv2.imshow('dawd',ini_depth)
cv2.waitKey(0)

Expand Down Expand Up @@ -131,7 +131,7 @@ def main():

if check_keyframe(T):
# If it is a keyframe, add it to K after finding depth and uncertainty map
depth = monodepth.get_cnn_depth(sess,image)
depth = monodepth_single.get_depth_map(sess,image)
cur_index += 1
uncertainty = find_uncertainty.get_uncertainty(T,D,K[cur_index - 1])
# T = np.append(T,np.array([[0,0,0,1]]),0)
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_without_cnn():
if check_keyframe(T):
print ("Error: second frame cant be keyframe\n")
# If it is a keyframe, add it to K after finding depth and uncertainty map
depth = monodepth.get_cnn_depth(sess,image)
depth = monodepth_single.get_cnn_depth(sess,image)
cur_index += 1
uncertainty = find_uncertainty.get_uncertainty(T,D,K[cur_index - 1])
T = np.append(T,np.array([[0,0,0,1]]),0)
Expand Down

0 comments on commit f03d5c2

Please sign in to comment.