Skip to content

Commit

Permalink
Make code compatible with tf1.0rc0.
Browse files Browse the repository at this point in the history
This addresses issues discussed in #20. The rc0 build can now be used to run this code.
  • Loading branch information
MarvinTeichmann committed Feb 2, 2017
1 parent 1766a01 commit ba49956
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
14 changes: 8 additions & 6 deletions fcn16_vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class FCN16VGG:

def __init__(self, vgg16_npy_path=None):
if vgg16_npy_path is None:
path = sys.modules[self.__class__.__module__].__file__
Expand Down Expand Up @@ -59,7 +60,7 @@ def build(self, rgb, train=False, num_classes=20, random_init_fc8=False,
# assert red.get_shape().as_list()[1:] == [224, 224, 1]
# assert green.get_shape().as_list()[1:] == [224, 224, 1]
# assert blue.get_shape().as_list()[1:] == [224, 224, 1]
bgr = tf.concat_v2([
bgr = tf.concat([
blue - VGG_MEAN[0],
green - VGG_MEAN[1],
red - VGG_MEAN[2]], axis=3)
Expand Down Expand Up @@ -268,8 +269,8 @@ def get_conv_filter(self, name):
print('Layer shape: %s' % str(shape))
var = tf.get_variable(name="filter", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand All @@ -290,8 +291,8 @@ def get_fc_weight(self, name):
shape = self.data_dict[name][0].shape
var = tf.get_variable(name="weights", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand Down Expand Up @@ -369,7 +370,8 @@ def _variable_with_weight_decay(self, shape, stddev, wd):
initializer=initializer)

if wd and (not tf.get_variable_scope().reuse):
weight_decay = tf.mul(tf.nn.l2_loss(var), wd, name='weight_loss')
weight_decay = tf.multiply(
tf.nn.l2_loss(var), wd, name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand Down
14 changes: 8 additions & 6 deletions fcn32_vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class FCN32VGG:

def __init__(self, vgg16_npy_path=None):
if vgg16_npy_path is None:
path = sys.modules[self.__class__.__module__].__file__
Expand Down Expand Up @@ -59,7 +60,7 @@ def build(self, rgb, train=False, num_classes=20, random_init_fc8=False,
# assert red.get_shape().as_list()[1:] == [224, 224, 1]
# assert green.get_shape().as_list()[1:] == [224, 224, 1]
# assert blue.get_shape().as_list()[1:] == [224, 224, 1]
bgr = tf.concat_v2([
bgr = tf.concat([
blue - VGG_MEAN[0],
green - VGG_MEAN[1],
red - VGG_MEAN[2],
Expand Down Expand Up @@ -253,8 +254,8 @@ def get_conv_filter(self, name):
print('Layer shape: %s' % str(shape))
var = tf.get_variable(name="filter", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand All @@ -275,8 +276,8 @@ def get_fc_weight(self, name):
shape = self.data_dict[name][0].shape
var = tf.get_variable(name="weights", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand Down Expand Up @@ -354,7 +355,8 @@ def _variable_with_weight_decay(self, shape, stddev, wd):
initializer=initializer)

if wd and (not tf.get_variable_scope().reuse):
weight_decay = tf.mul(tf.nn.l2_loss(var), wd, name='weight_loss')
weight_decay = tf.multiply(
tf.nn.l2_loss(var), wd, name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var

Expand Down
17 changes: 10 additions & 7 deletions fcn8_vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class FCN8VGG:

def __init__(self, vgg16_npy_path=None):
if vgg16_npy_path is None:
path = sys.modules[self.__class__.__module__].__file__
Expand Down Expand Up @@ -59,7 +60,7 @@ def build(self, rgb, train=False, num_classes=20, random_init_fc8=False,
# assert red.get_shape().as_list()[1:] == [224, 224, 1]
# assert green.get_shape().as_list()[1:] == [224, 224, 1]
# assert blue.get_shape().as_list()[1:] == [224, 224, 1]
bgr = tf.concat_v2([
bgr = tf.concat([
blue - VGG_MEAN[0],
green - VGG_MEAN[1],
red - VGG_MEAN[2],
Expand Down Expand Up @@ -284,8 +285,8 @@ def get_conv_filter(self, name):
print('Layer shape: %s' % str(shape))
var = tf.get_variable(name="filter", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
_variable_summaries(var)
return var
Expand All @@ -309,8 +310,8 @@ def get_fc_weight(self, name):
shape = self.data_dict[name][0].shape
var = tf.get_variable(name="weights", initializer=init, shape=shape)
if not tf.get_variable_scope().reuse:
weight_decay = tf.mul(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
weight_decay = tf.multiply(tf.nn.l2_loss(var), self.wd,
name='weight_loss')
tf.add_to_collection('losses', weight_decay)
_variable_summaries(var)
return var
Expand Down Expand Up @@ -389,7 +390,8 @@ def _variable_with_weight_decay(self, shape, stddev, wd, decoder=False):
initializer=initializer)

if wd and (not tf.get_variable_scope().reuse):
weight_decay = tf.mul(tf.nn.l2_loss(var), wd, name='weight_loss')
weight_decay = tf.multiply(
tf.nn.l2_loss(var), wd, name='weight_loss')
if not decoder:
tf.add_to_collection('losses', weight_decay)
else:
Expand All @@ -399,7 +401,8 @@ def _variable_with_weight_decay(self, shape, stddev, wd, decoder=False):

def _add_wd_and_summary(self, var, wd, collection_name="losses"):
if wd and (not tf.get_variable_scope().reuse):
weight_decay = tf.mul(tf.nn.l2_loss(var), wd, name='weight_loss')
weight_decay = tf.multiply(
tf.nn.l2_loss(var), wd, name='weight_loss')
tf.add_to_collection(collection_name, weight_decay)
_variable_summaries(var)
return var
Expand Down

0 comments on commit ba49956

Please sign in to comment.