in models.py [0:0]
def forward(self, inp, weights, reuse=False, scope='', stop_grad=False, label=None, stop_at_grad=False, stop_batch=False):
weights = weights.copy()
batch = tf.shape(inp)[0]
act = tf.nn.leaky_relu
if not FLAGS.cclass:
label = None
if stop_grad:
for k, v in weights.items():
if type(v) == dict:
v = v.copy()
weights[k] = v
for k_sub, v_sub in v.items():
v[k_sub] = tf.stop_gradient(v_sub)
else:
weights[k] = tf.stop_gradient(v)
# Make sure gradients are modified a bit
inp = smart_conv_block(inp, weights, reuse, 'c1_pre', use_stride=False)
hidden1 = smart_res_block(inp, weights, reuse, 'res_optim', adaptive=False, label=label, act=act)
hidden2 = smart_res_block(hidden1, weights, reuse, 'res_1', stop_batch=stop_batch, downsample=False, adaptive=False, label=label, act=act)
hidden3 = smart_res_block(hidden2, weights, reuse, 'res_2', stop_batch=stop_batch, label=label, act=act)
if FLAGS.use_attention:
hidden4 = smart_atten_block(hidden3, weights, reuse, 'atten', stop_at_grad=stop_at_grad, label=label)
else:
hidden4 = smart_res_block(hidden3, weights, reuse, 'res_3', adaptive=False, downsample=False, stop_batch=stop_batch, label=label, act=act)
hidden5 = smart_res_block(hidden4, weights, reuse, 'res_4', stop_batch=stop_batch, adaptive=False, label=label, act=act)
compact = hidden6 = smart_res_block(hidden5, weights, reuse, 'res_5', adaptive=False, downsample=False, stop_batch=stop_batch, label=label)
hidden6 = tf.nn.relu(hidden6)
hidden5 = tf.reduce_sum(hidden6, [1, 2])
hidden6 = smart_fc_block(hidden5, weights, reuse, 'fc5')
energy = hidden6
return energy