Commit fdc90767 authored by Yuxin Wu's avatar Yuxin Wu

fix use of deprecated TF functions.

parent 453b7c63
...@@ -49,8 +49,8 @@ class Model(mnist_example.Model): ...@@ -49,8 +49,8 @@ class Model(mnist_example.Model):
cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, label) cost = tf.nn.sparse_softmax_cross_entropy_with_logits(logits, label)
cost = tf.reduce_mean(cost, name='cross_entropy_loss') cost = tf.reduce_mean(cost, name='cross_entropy_loss')
wd_cost = tf.mul(1e-5, regularize_cost('fc.*/W', tf.nn.l2_loss), wd_cost = tf.multiply(1e-5, regularize_cost('fc.*/W', tf.nn.l2_loss),
name='regularize_loss') name='regularize_loss')
self.cost = tf.add_n([wd_cost, cost], name='cost') self.cost = tf.add_n([wd_cost, cost], name='cost')
add_moving_summary(cost, wd_cost, self.cost) add_moving_summary(cost, wd_cost, self.cost)
......
...@@ -107,7 +107,7 @@ class Model(ModelDesc): ...@@ -107,7 +107,7 @@ class Model(ModelDesc):
.BatchNorm('lastbn') .BatchNorm('lastbn')
.apply(nonlin) .apply(nonlin)
.GlobalAvgPooling('gap') .GlobalAvgPooling('gap')
.tf.mul(49) # this is due to a bug in our model design .tf.multiply(49) # this is due to a bug in our model design
.FullyConnected('fct', 1000)()) .FullyConnected('fct', 1000)())
prob = tf.nn.softmax(logits, name='output') prob = tf.nn.softmax(logits, name='output')
wrong = prediction_incorrect(logits, label, 1, name='wrong-top1') wrong = prediction_incorrect(logits, label, 1, name='wrong-top1')
......
...@@ -59,15 +59,15 @@ def build_GAN_losses(vecpos, vecneg): ...@@ -59,15 +59,15 @@ def build_GAN_losses(vecpos, vecneg):
tf.summary.histogram('sigmoid-neg', sigmneg) tf.summary.histogram('sigmoid-neg', sigmneg)
d_loss_pos = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits( d_loss_pos = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecpos, tf.ones_like(vecpos)), name='d_CE_loss_pos') logits=vecpos, labels=tf.ones_like(vecpos)), name='d_CE_loss_pos')
d_loss_neg = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits( d_loss_neg = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecneg, tf.zeros_like(vecneg)), name='d_CE_loss_neg') logits=vecneg, labels=tf.zeros_like(vecneg)), name='d_CE_loss_neg')
d_pos_acc = tf.reduce_mean(tf.cast(sigmpos > 0.5, tf.float32), name='pos_acc') d_pos_acc = tf.reduce_mean(tf.cast(sigmpos > 0.5, tf.float32), name='pos_acc')
d_neg_acc = tf.reduce_mean(tf.cast(sigmneg < 0.5, tf.float32), name='neg_acc') d_neg_acc = tf.reduce_mean(tf.cast(sigmneg < 0.5, tf.float32), name='neg_acc')
g_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits( g_loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(
vecneg, tf.ones_like(vecneg)), name='g_CE_loss') logits=vecneg, labels=tf.ones_like(vecneg)), name='g_CE_loss')
d_loss = tf.add(d_loss_pos, d_loss_neg, name='d_CE_loss') d_loss = tf.add(d_loss_pos, d_loss_neg, name='d_CE_loss')
add_moving_summary(d_loss_pos, d_loss_neg, add_moving_summary(d_loss_pos, d_loss_neg,
g_loss, d_loss, g_loss, d_loss,
......
...@@ -81,7 +81,7 @@ class Model(ModelDesc): ...@@ -81,7 +81,7 @@ class Model(ModelDesc):
log_qc = tf.reduce_sum(prior_prob * zc, 1, name='logQc') log_qc = tf.reduce_sum(prior_prob * zc, 1, name='logQc')
Elog_qc_given_x = tf.reduce_mean(log_qc_given_x, name='ElogQc_x') Elog_qc_given_x = tf.reduce_mean(log_qc_given_x, name='ElogQc_x')
Hc = tf.reduce_mean(-log_qc, name='Hc') Hc = tf.reduce_mean(-log_qc, name='Hc')
MIloss = tf.mul(Hc + Elog_qc_given_x, -1.0, name='neg_MI') MIloss = tf.multiply(Hc + Elog_qc_given_x, -1.0, name='neg_MI')
self.g_loss, self.d_loss = build_GAN_losses(vecpos, vecneg) self.g_loss, self.d_loss = build_GAN_losses(vecpos, vecneg)
self.g_loss = tf.add(self.g_loss, MIloss, name='total_g_loss') self.g_loss = tf.add(self.g_loss, MIloss, name='total_g_loss')
......
...@@ -86,7 +86,7 @@ class Model(ModelDesc): ...@@ -86,7 +86,7 @@ class Model(ModelDesc):
if get_current_tower_context().is_training: if get_current_tower_context().is_training:
wd_w = tf.train.exponential_decay(2e-4, get_global_step_var(), wd_w = tf.train.exponential_decay(2e-4, get_global_step_var(),
80000, 0.7, True) 80000, 0.7, True)
wd_cost = tf.mul(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='wd_cost') wd_cost = tf.multiply(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='wd_cost')
costs.append(wd_cost) costs.append(wd_cost)
add_param_summary(('.*/W', ['histogram'])) # monitor W add_param_summary(('.*/W', ['histogram'])) # monitor W
......
...@@ -113,7 +113,7 @@ class Model(ModelDesc): ...@@ -113,7 +113,7 @@ class Model(ModelDesc):
# weight decay on all W of fc layers # weight decay on all W of fc layers
wd_w = tf.train.exponential_decay(0.0002, get_global_step_var(), wd_w = tf.train.exponential_decay(0.0002, get_global_step_var(),
80000, 0.7, True) 80000, 0.7, True)
wd_cost = tf.mul(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='l2_regularize_loss') wd_cost = tf.multiply(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='l2_regularize_loss')
add_param_summary(('.*/W', ['histogram'])) # monitor W add_param_summary(('.*/W', ['histogram'])) # monitor W
self.cost = tf.add_n([cost, wd_cost], name='cost') self.cost = tf.add_n([cost, wd_cost], name='cost')
......
...@@ -192,7 +192,7 @@ class Model(ModelDesc): ...@@ -192,7 +192,7 @@ class Model(ModelDesc):
# weight decay on all W of fc layers # weight decay on all W of fc layers
wd_w = tf.train.exponential_decay(0.00004, get_global_step_var(), wd_w = tf.train.exponential_decay(0.00004, get_global_step_var(),
80000, 0.7, True) 80000, 0.7, True)
wd_cost = tf.mul(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='l2_regularize_loss') wd_cost = tf.multiply(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='l2_regularize_loss')
self.cost = tf.add_n([0.4 * loss1, loss2, wd_cost], name='cost') self.cost = tf.add_n([0.4 * loss1, loss2, wd_cost], name='cost')
add_moving_summary(loss1, loss2, wd_cost, self.cost) add_moving_summary(loss1, loss2, wd_cost, self.cost)
......
...@@ -115,7 +115,7 @@ class Model(ModelDesc): ...@@ -115,7 +115,7 @@ class Model(ModelDesc):
log_pi_a_given_s = tf.reduce_sum( log_pi_a_given_s = tf.reduce_sum(
log_probs * tf.one_hot(action, NUM_ACTIONS), 1) log_probs * tf.one_hot(action, NUM_ACTIONS), 1)
advantage = tf.sub(tf.stop_gradient(self.value), futurereward, name='advantage') advantage = tf.subtract(tf.stop_gradient(self.value), futurereward, name='advantage')
policy_loss = tf.reduce_sum(log_pi_a_given_s * advantage, name='policy_loss') policy_loss = tf.reduce_sum(log_pi_a_given_s * advantage, name='policy_loss')
xentropy_loss = tf.reduce_sum( xentropy_loss = tf.reduce_sum(
self.logits * log_probs, name='xentropy_loss') self.logits * log_probs, name='xentropy_loss')
......
...@@ -100,7 +100,7 @@ class Model(ModelDesc): ...@@ -100,7 +100,7 @@ class Model(ModelDesc):
# weight decay on all W of fc layers # weight decay on all W of fc layers
wd_w = tf.train.exponential_decay(0.0002, get_global_step_var(), wd_w = tf.train.exponential_decay(0.0002, get_global_step_var(),
480000, 0.2, True) 480000, 0.2, True)
wd_cost = tf.mul(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='wd_cost') wd_cost = tf.multiply(wd_w, regularize_cost('.*/W', tf.nn.l2_loss), name='wd_cost')
add_moving_summary(cost, wd_cost) add_moving_summary(cost, wd_cost)
add_param_summary(('.*/W', ['histogram'])) # monitor W add_param_summary(('.*/W', ['histogram'])) # monitor W
......
...@@ -111,7 +111,7 @@ class Model(ModelDesc): ...@@ -111,7 +111,7 @@ class Model(ModelDesc):
wrong = prediction_incorrect(logits, label, 5, name='wrong-top5') wrong = prediction_incorrect(logits, label, 5, name='wrong-top5')
add_moving_summary(tf.reduce_mean(wrong, name='train-error-top5')) add_moving_summary(tf.reduce_mean(wrong, name='train-error-top5'))
wd_cost = tf.mul(1e-4, regularize_cost('.*/W', tf.nn.l2_loss), name='l2_regularize_loss') wd_cost = regularize_cost('.*/W', l2_regularizer(1e-4), name='l2_regularize_loss')
add_moving_summary(loss, wd_cost) add_moving_summary(loss, wd_cost)
self.cost = tf.add_n([loss, wd_cost], name='cost') self.cost = tf.add_n([loss, wd_cost], name='cost')
......
...@@ -81,8 +81,8 @@ class Model(ModelDesc): ...@@ -81,8 +81,8 @@ class Model(ModelDesc):
wrong = symbolic_functions.prediction_incorrect(logits, label) wrong = symbolic_functions.prediction_incorrect(logits, label)
summary.add_moving_summary(tf.reduce_mean(wrong, name='train_error')) summary.add_moving_summary(tf.reduce_mean(wrong, name='train_error'))
wd_cost = tf.mul(1e-5, regularize_cost('fc.*/W', tf.nn.l2_loss), wd_cost = tf.multiply(1e-5, regularize_cost('fc.*/W', tf.nn.l2_loss),
name='regularize_loss') name='regularize_loss')
summary.add_moving_summary(cost, wd_cost) summary.add_moving_summary(cost, wd_cost)
self.cost = tf.add_n([wd_cost, cost], name='cost') self.cost = tf.add_n([wd_cost, cost], name='cost')
......
...@@ -66,9 +66,7 @@ class Model(ModelDesc): ...@@ -66,9 +66,7 @@ class Model(ModelDesc):
add_moving_summary(tf.reduce_mean(wrong, name='train_error')) add_moving_summary(tf.reduce_mean(wrong, name='train_error'))
# weight decay on all W of fc layers # weight decay on all W of fc layers
wd_cost = tf.mul(0.0004, wd_cost = regularize_cost('fc.*/W', l2_regularizer(4e-4), name='regularize_loss')
regularize_cost('fc.*/W', tf.nn.l2_loss),
name='regularize_loss')
add_moving_summary(cost, wd_cost) add_moving_summary(cost, wd_cost)
add_param_summary(('.*/W', ['histogram'])) # monitor W add_param_summary(('.*/W', ['histogram'])) # monitor W
......
...@@ -96,9 +96,9 @@ class Model(ModelDesc): ...@@ -96,9 +96,9 @@ class Model(ModelDesc):
if not USE_SLIM: if not USE_SLIM:
# Use a regex to find parameters to apply weight decay. # Use a regex to find parameters to apply weight decay.
# Here we apply a weight decay on all W (weight matrix) of all fc layers # Here we apply a weight decay on all W (weight matrix) of all fc layers
wd_cost = tf.mul(1e-5, wd_cost = tf.multiply(1e-5,
regularize_cost('fc.*/W', tf.nn.l2_loss), regularize_cost('fc.*/W', tf.nn.l2_loss),
name='regularize_loss') name='regularize_loss')
self.cost = tf.add_n([wd_cost, cost], name='total_cost') self.cost = tf.add_n([wd_cost, cost], name='total_cost')
summary.add_moving_summary(cost, wd_cost, self.cost) summary.add_moving_summary(cost, wd_cost, self.cost)
else: else:
......
...@@ -18,7 +18,11 @@ def global_import(name): ...@@ -18,7 +18,11 @@ def global_import(name):
__all__.append(k) __all__.append(k)
_CURR_DIR = os.path.dirname(__file__)
for _, module_name, _ in walk_packages( for _, module_name, _ in walk_packages(
[os.path.dirname(__file__)]): [_CURR_DIR]):
srcpath = os.path.join(_CURR_DIR, module_name + '.py')
if not os.path.isfile(srcpath):
continue
if not module_name.startswith('_'): if not module_name.startswith('_'):
global_import(module_name) global_import(module_name)
...@@ -50,7 +50,7 @@ def PReLU(x, init=0.001, name='output'): ...@@ -50,7 +50,7 @@ def PReLU(x, init=0.001, name='output'):
init = tf.constant_initializer(init) init = tf.constant_initializer(init)
alpha = tf.get_variable('alpha', [], initializer=init) alpha = tf.get_variable('alpha', [], initializer=init)
x = ((1 + alpha) * x + (1 - alpha) * tf.abs(x)) x = ((1 + alpha) * x + (1 - alpha) * tf.abs(x))
return tf.mul(x, 0.5, name=name) return tf.multiply(x, 0.5, name=name)
@layer_register(use_scope=False, log_shape=False) @layer_register(use_scope=False, log_shape=False)
......
...@@ -59,7 +59,7 @@ def class_balanced_cross_entropy(pred, label, name='cross_entropy_loss'): ...@@ -59,7 +59,7 @@ def class_balanced_cross_entropy(pred, label, name='cross_entropy_loss'):
eps = 1e-12 eps = 1e-12
loss_pos = -beta * tf.reduce_mean(y * tf.log(z + eps)) loss_pos = -beta * tf.reduce_mean(y * tf.log(z + eps))
loss_neg = (1. - beta) * tf.reduce_mean((1. - y) * tf.log(1. - z + eps)) loss_neg = (1. - beta) * tf.reduce_mean((1. - y) * tf.log(1. - z + eps))
cost = tf.sub(loss_pos, loss_neg, name=name) cost = tf.subtract(loss_pos, loss_neg, name=name)
return cost return cost
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment