Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify code #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions bts.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def reduction_1x1(self, net, num_filters, is_final=False):
net = self.conv(net, 1, 1, 1, activation_fn=tf.nn.sigmoid)
else:
net = self.conv(net, 3, 1, 1, activation_fn=None)
theta = tf.nn.sigmoid(net[:, :, :, 0]) * 3.1415926535 / 6
phi = tf.nn.sigmoid(net[:, :, :, 1]) * 3.1415926535 * 2
dist = tf.nn.sigmoid(net[:, :, :, 2]) * self.max_depth
n1 = tf.expand_dims(tf.multiply(tf.math.sin(theta), tf.math.cos(phi)), 3)
n2 = tf.expand_dims(tf.multiply(tf.math.sin(theta), tf.math.sin(phi)), 3)
n3 = tf.expand_dims(tf.math.cos(theta), 3)
n4 = tf.expand_dims(dist, 3)
theta = tf.nn.sigmoid(net[:, :, :, 0:1]) * np.pi / 6
phi = tf.nn.sigmoid(net[:, :, :, 1:2]) * np.pi * 2
dist = tf.nn.sigmoid(net[:, :, :, 2:3]) * self.max_depth
n1 = tf.sin(theta) * tf.cos(phi)
n2 = tf.sin(theta) * tf.sin(phi)
n3 = tf.cos(theta)
n4 = dist
net = tf.concat([n1, n2, n3, n4], axis=3)
break
else:
Expand All @@ -169,12 +169,12 @@ def reduction_1x1(self, net, num_filters, is_final=False):

def get_depth(self, x):
depth = self.max_depth * self.conv(x, 1, 3, 1, tf.nn.sigmoid, normalizer_fn=None)
#b = 1 if self.params.batch_size is None else self.params.batch_size
focal_expanded = tf.reshape(self.focal, [-1, 1, 1, 1])
if self.params.dataset == 'kitti':
focal_expanded = tf.expand_dims(self.focal, 1)
focal_expanded = tf.expand_dims(focal_expanded, 1)
focal_expanded = tf.expand_dims(focal_expanded, 1)
depth = depth * focal_expanded / 715.0873 # Average focal length in KITTI Eigen training set
return depth


def densenet(self, inputs, reduction=None, growth_rate=None, num_filters=None, num_layers=None, dropout_rate=None,
is_training=True, reuse=None, scope=None):
Expand Down Expand Up @@ -276,8 +276,8 @@ def bts(self, dense_features, skips, num_filters=256):

plane_eq_8x8 = self.reduction_1x1(daspp_feat, num_filters / 2)
plane_normal_8x8 = tf.nn.l2_normalize(plane_eq_8x8[:, :, :, 0:3], axis=3)
plane_dist_8x8 = plane_eq_8x8[:, :, :, 3]
plane_eq_8x8 = tf.concat([plane_normal_8x8, tf.expand_dims(plane_dist_8x8, 3)], 3)
plane_dist_8x8 = plane_eq_8x8[:, :, :, 3:4]
plane_eq_8x8 = tf.concat([plane_normal_8x8, plane_dist_8x8], 3)
depth_8x8 = lpg.local_planar_guidance(plane_eq_8x8, upratio=8, focal=self.focal)
depth_8x8_scaled = tf.expand_dims(depth_8x8, 3) / self.max_depth
depth_8x8_scaled_ds = self.downsample_nn(depth_8x8_scaled, 4)
Expand All @@ -291,8 +291,8 @@ def bts(self, dense_features, skips, num_filters=256):

plane_eq_4x4 = self.reduction_1x1(iconv3, num_filters / 2)
plane_normal_4x4 = tf.nn.l2_normalize(plane_eq_4x4[:, :, :, 0:3], axis=3)
plane_dist_4x4 = plane_eq_4x4[:, :, :, 3]
plane_eq_4x4 = tf.concat([plane_normal_4x4, tf.expand_dims(plane_dist_4x4, 3)], 3)
plane_dist_4x4 = plane_eq_4x4[:, :, :, 3:4]
plane_eq_4x4 = tf.concat([plane_normal_4x4, plane_dist_4x4], 3)
depth_4x4 = lpg.local_planar_guidance(plane_eq_4x4, upratio=4, focal=self.focal)
depth_4x4_scaled = tf.expand_dims(depth_4x4, 3) / self.max_depth
depth_4x4_scaled_ds = self.downsample_nn(depth_4x4_scaled, 2)
Expand All @@ -306,8 +306,8 @@ def bts(self, dense_features, skips, num_filters=256):

plane_eq_2x2 = self.reduction_1x1(iconv2, num_filters / 2)
plane_normal_2x2 = tf.nn.l2_normalize(plane_eq_2x2[:, :, :, 0:3], axis=3)
plane_dist_2x2 = plane_eq_2x2[:, :, :, 3]
plane_eq_2x2 = tf.concat([plane_normal_2x2, tf.expand_dims(plane_dist_2x2, 3)], 3)
plane_dist_2x2 = plane_eq_2x2[:, :, :, 3:4]
plane_eq_2x2 = tf.concat([plane_normal_2x2, plane_dist_2x2], 3)
depth_2x2 = lpg.local_planar_guidance(plane_eq_2x2, upratio=2, focal=self.focal)
depth_2x2_scaled = tf.expand_dims(depth_2x2, 3) / self.max_depth

Expand Down Expand Up @@ -457,4 +457,4 @@ def build_summaries(self):
tf.summary.image('lpg2x2', 1 / self.lpg2x2, max_outputs=4, collections=self.model_collection)
tf.summary.image('lpg4x4', 1 / self.lpg4x4, max_outputs=4, collections=self.model_collection)
tf.summary.image('lpg8x8', 1 / self.lpg8x8, max_outputs=4, collections=self.model_collection)
tf.summary.image('image', self.input_image, max_outputs=4, collections=self.model_collection)
tf.summary.image('image', self.input_image, max_outputs=4, collections=self.model_collection)