Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 11 additions & 8 deletions core/evaluator_interactive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import tensorflow as tf
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
import numpy as np
Expand Down Expand Up @@ -38,15 +40,15 @@ def construct_graph(eval_config):
depth_320, depth_net = build_depth_resnet.build(image_320_tensor, is_training)
focal_depth = depth_320[0, focal_y_tensor, focal_x_tensor, 0]
depth_320_signed = (depth_320 - focal_depth) * aperture_tensor
pre_dof_320, lensblur_net, feature_net = build_lensblur.build(image_320_tensor, depth_320_signed, is_training)
pre_dof_320, lensblur_net, feature_net = build_lensblur.build(image_320_tensor, depth_320_signed, is_training)
pre_dof_640, sr_net = build_sr.build(image_320_tensor, depth_320_signed, pre_dof_320, image_640_tensor, is_training)
shape_640 = tf.shape(pre_dof_640)
depth_640_signed = tf.image.resize_bilinear(depth_320_signed, [shape_640[1], shape_640[2]])
pre_dof_1280, sr_net = build_sr.build(image_640_tensor, depth_640_signed, pre_dof_640, image_1280_tensor, is_training)
pre_dof_1280, sr_net = build_sr.build(image_640_tensor, depth_640_signed, pre_dof_640, image_1280_tensor, is_training)


variables_to_restore = tf.global_variables()

session_config = tf.ConfigProto()
session_config.gpu_options.per_process_gpu_memory_fraction = 0.8
sess = tf.Session(config=session_config)
Expand All @@ -65,7 +67,7 @@ def construct_graph(eval_config):
else:
raise ValueError("No pre-trained models")


def pre_dof(im):
focal_x, focal_y = im.get_focal_point()
aperture = im.aperture
Expand Down Expand Up @@ -105,6 +107,7 @@ def evaluate(eval_config):
depth_handle = plt.imshow(pre_depth[0,:,:,0])
renderdof = RenderDoF(im_handle, depth_handle, slider, im, run_dof_func, run_depth_func, start_id, image_names)
plt.show()
#plt.savefig('output.jpg')

def _normalize(x):
x = x.astype(np.float32)
Expand All @@ -121,13 +124,13 @@ def __init__(self, im, depth=None, dof=None, x=0, y=0, aperture=1.0):
self.scale = 4
self.im_1280 = im
#self.im_1280 = cv2.resize(self.im, (self.im.shape[1]/2, self.im.shape[0]/2), interpolation=cv2.INTER_AREA)
self.im_640 = cv2.resize(self.im_1280, (self.im_1280.shape[1]/2, self.im_1280.shape[0]/2), interpolation=cv2.INTER_AREA)
self.im_320 = cv2.resize(self.im_640, (self.im_640.shape[1]/2, self.im_640.shape[0]/2), interpolation=cv2.INTER_AREA)
self.im_640 = cv2.resize(self.im_1280, (int(self.im_1280.shape[1]/2), int(self.im_1280.shape[0]/2)), interpolation=cv2.INTER_AREA)
self.im_320 = cv2.resize(self.im_640, (int(self.im_640.shape[1]/2),int(self.im_640.shape[0]/2)), interpolation=cv2.INTER_AREA)
elif np.max(im.shape) > 640:
self.scale = 2
self.im_1280 = None
self.im_640 = im
self.im_320 = cv2.resize(self.im_640, (self.im_640.shape[1]/2, self.im_640.shape[0]/2), interpolation=cv2.INTER_AREA)
self.im_320 = cv2.resize(self.im_640, (int(self.im_640.shape[1]/2), int(self.im_640.shape[0]/2)), interpolation=cv2.INTER_AREA)
else:
self.scale = 1
self.im_1280 = None
Expand Down Expand Up @@ -208,7 +211,7 @@ def on_key(self, event):
im = im.astype(np.float32) / 255
im = ImageWrapper(im, aperture=self.slider.val/10.0)
self.im = im
print self.im_names[self.id]
print(self.im_names[self.id])
except:
start_id = self.id
exit()
Expand Down
2 changes: 1 addition & 1 deletion eval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tensorflow as tf

from network.network import Network
from google.protobuf import text_format
from proto.eval_config_pb2 import EvalConfig
from core import evaluator_interactive as evaluator
Expand Down
2 changes: 1 addition & 1 deletion model/eval.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
depth_ckpt: './model/model_depth/model.ckpt-346224'
depth_ckpt: './model/model_depth/model-346224'
lensblur_ckpt: 'model/model_lensblur/model-199950'
res_path: './data/res/'
image_path: "./data/imgs/"
Expand Down
2 changes: 1 addition & 1 deletion network/feature_net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from network import Network
from network.network import Network

class FeaNet(Network):
def __init__(self, input, is_training, trainable=True, bn_global=None, upsample_size=640):
Expand Down
4 changes: 2 additions & 2 deletions network/kernel_net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from network import Network
from network.network import Network
import tensorflow as tf

class KernelNet(Network):
Expand Down Expand Up @@ -64,7 +64,7 @@ def setup(self):
self.resize(shape=tf.shape(self.layers['image'])[1:3], name='upsample')

#concat
(self.feed('upsample',
(self.feed('upsample',
'bn1_shallow')
.concat(3, name='concat'))

Expand Down
10 changes: 5 additions & 5 deletions network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def feed(self, *args):
assert len(args) != 0
self.terminals = []
for fed_layer in args:
if isinstance(fed_layer, basestring):
if isinstance(fed_layer, str):
try:
fed_layer = self.layers[fed_layer]
except KeyError:
Expand All @@ -102,7 +102,7 @@ def get_unique_name(self, prefix):
'''
ident = sum(t.startswith(prefix) for t, _ in self.layers.items()) + 1
return '%s_%d' % (prefix, ident)

def make_var(self, name, shape, weight_decay=0, trainable=None, initializer=None):
'''Creates a new TensorFlow variable.'''
if trainable == None:
Expand Down Expand Up @@ -139,7 +139,7 @@ def conv(self,
# Verify that the padding is acceptable
self.validate_padding(padding)
# Get the number of channels in the input
c_i = input.get_shape()[-1]
c_i = input.get_shape().as_list()[-1]
# Verify that the grouping parameter is valid
assert c_i % group == 0
assert c_o % group == 0
Expand Down Expand Up @@ -191,7 +191,7 @@ def separable_conv(self,
# Convolution for a given input and kernel
if dilation_rate > 1:
assert s_h == 1 and s_w == 1
separable_convolve = lambda i, k_depth, k_point: tf.nn.separable_conv2d(i, k_depth, k_point, strides=[1, s_h, s_w, 1],
separable_convolve = lambda i, k_depth, k_point: tf.nn.separable_conv2d(i, k_depth, k_point, strides=[1, s_h, s_w, 1],
rate=[dilation_rate, dilation_rate], padding=padding, name=name)
with tf.variable_scope(name) as scope:
#kernel = self.make_var('weights', shape=[k_h, k_w, c_i / group, c_o])
Expand Down Expand Up @@ -302,7 +302,7 @@ def add(self, inputs, name):
@layer
def fc(self, input, num_out, name, relu=True):
with tf.variable_scope(name) as scope:
input_shape = input.get_shape()
input_shape = input.get_shape().as_list()
if input_shape.ndims == 4:
# The input is spatial. Vectorize it first.
dim = 1
Expand Down
28 changes: 14 additions & 14 deletions network/resnet50_lrelu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from network import Network
from network.network import Network
import tensorflow as tf

class ResNet50(Network):
Expand All @@ -22,7 +22,7 @@ def setup(self):
.conv(1, 1, 256, 1, 1, 1, biased=False, relu=False, name='res2a_branch2c')
.batch_normalization(name='bn2a_branch2c'))

(self.feed('bn2a_branch1',
(self.feed('bn2a_branch1',
'bn2a_branch2c')
.add(name='res2a')
.relu(name='res2a_relu')
Expand All @@ -33,7 +33,7 @@ def setup(self):
.conv(1, 1, 256, 1, 1, 1, biased=False, relu=False, name='res2b_branch2c')
.batch_normalization(name='bn2b_branch2c'))

(self.feed('res2a_relu',
(self.feed('res2a_relu',
'bn2b_branch2c')
.add(name='res2b')
.relu(name='res2b_relu')
Expand All @@ -44,7 +44,7 @@ def setup(self):
.conv(1, 1, 256, 1, 1, 1, biased=False, relu=False, name='res2c_branch2c')
.batch_normalization(name='bn2c_branch2c'))

(self.feed('res2b_relu',
(self.feed('res2b_relu',
'bn2c_branch2c')
.add(name='res2c')
.relu(name='res2c_relu')
Expand All @@ -59,7 +59,7 @@ def setup(self):
.conv(1, 1, 512, 1, 1, 1, biased=False, relu=False, name='res3a_branch2c')
.batch_normalization(name='bn3a_branch2c'))

(self.feed('bn3a_branch1',
(self.feed('bn3a_branch1',
'bn3a_branch2c')
.add(name='res3a')
.relu(name='res3a_relu')
Expand All @@ -70,7 +70,7 @@ def setup(self):
.conv(1, 1, 512, 1, 1, 1, biased=False, relu=False, name='res3b_branch2c')
.batch_normalization(name='bn3b_branch2c'))

(self.feed('res3a_relu',
(self.feed('res3a_relu',
'bn3b_branch2c')
.add(name='res3b')
.relu(name='res3b_relu')
Expand All @@ -81,7 +81,7 @@ def setup(self):
.conv(1, 1, 512, 1, 1, 1, biased=False, relu=False, name='res3c_branch2c')
.batch_normalization(name='bn3c_branch2c'))

(self.feed('res3b_relu',
(self.feed('res3b_relu',
'bn3c_branch2c')
.add(name='res3c')
.relu(name='res3c_relu')
Expand All @@ -92,7 +92,7 @@ def setup(self):
.conv(1, 1, 512, 1, 1, 1, biased=False, relu=False, name='res3d_branch2c')
.batch_normalization(name='bn3d_branch2c'))

(self.feed('res3c_relu',
(self.feed('res3c_relu',
'bn3d_branch2c')
.add(name='res3d')
.relu(name='res3d_relu')
Expand All @@ -107,7 +107,7 @@ def setup(self):
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4a_branch2c')
.batch_normalization(name='bn4a_branch2c'))

(self.feed('bn4a_branch1',
(self.feed('bn4a_branch1',
'bn4a_branch2c')
.add(name='res4a')
.relu(name='res4a_relu')
Expand All @@ -118,7 +118,7 @@ def setup(self):
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4b_branch2c')
.batch_normalization(name='bn4b_branch2c'))

(self.feed('res4a_relu',
(self.feed('res4a_relu',
'bn4b_branch2c')
.add(name='res4b')
.relu(name='res4b_relu')
Expand All @@ -129,7 +129,7 @@ def setup(self):
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4c_branch2c')
.batch_normalization(name='bn4c_branch2c'))

(self.feed('res4b_relu',
(self.feed('res4b_relu',
'bn4c_branch2c')
.add(name='res4c')
.relu(name='res4c_relu')
Expand All @@ -140,7 +140,7 @@ def setup(self):
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4d_branch2c')
.batch_normalization(name='bn4d_branch2c'))

(self.feed('res4c_relu',
(self.feed('res4c_relu',
'bn4d_branch2c')
.add(name='res4d')
.relu(name='res4d_relu')
Expand All @@ -151,7 +151,7 @@ def setup(self):
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4e_branch2c')
.batch_normalization(name='bn4e_branch2c'))

(self.feed('res4d_relu',
(self.feed('res4d_relu',
'bn4e_branch2c')
.add(name='res4e')
.relu(name='res4e_relu')
Expand All @@ -161,7 +161,7 @@ def setup(self):
.batch_normalization(relu=True, name='bn4f_branch2b')
.conv(1, 1, 1024, 1, 1, 1, biased=False, relu=False, name='res4f_branch2c')
.batch_normalization(name='bn4f_branch2c'))
(self.feed('res4e_relu',
(self.feed('res4e_relu',
'bn4f_branch2c')
.add(name='res4f')
.relu(name='res4f_relu'))
Expand Down
2 changes: 1 addition & 1 deletion network/srnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from network import Network
from network.network import Network
import tensorflow as tf

class SRNet(Network):
Expand Down