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]
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)
if FLAGS.swish_act:
act = swish
else:
act = tf.nn.leaky_relu
dropout = self.dropout
train = self.train
# Make sure gradients are modified a bit
inp = smart_conv_block(inp, weights, reuse, 'c1_pre', use_stride=False, activation=act)
hidden1 = smart_res_block(inp, weights, reuse, 'res_optim', label=label, dropout=dropout, train=train, downsample=True, adaptive=False)
if FLAGS.use_attention:
hidden1 = smart_atten_block(hidden1, weights, reuse, 'atten', stop_at_grad=stop_at_grad)
hidden2 = smart_res_block(hidden1, weights, reuse, 'res_3', stop_batch=stop_batch, downsample=True, adaptive=True, label=label, dropout=dropout, train=train, act=act)
hidden3 = smart_res_block(hidden2, weights, reuse, 'res_5', stop_batch=stop_batch, downsample=True, adaptive=True, label=label, dropout=dropout, train=train, act=act)
hidden4 = smart_res_block(hidden3, weights, reuse, 'res_7', stop_batch=stop_batch, label=label, dropout=dropout, train=train, act=act, downsample=True, adaptive=True)
hidden5 = smart_res_block(hidden4, weights, reuse, 'res_9', stop_batch=stop_batch, label=label, dropout=dropout, train=train, act=act, downsample=True, adaptive=False)
hidden6 = smart_res_block(hidden5, weights, reuse, 'res_10', stop_batch=stop_batch, label=label, dropout=dropout, train=train, act=act, downsample=False, adaptive=False)
if FLAGS.swish_act:
hidden6 = act(hidden6)
else:
hidden6 = tf.nn.relu(hidden6)
hidden5 = tf.reduce_sum(hidden6, [1, 2])
hidden6 = smart_fc_block(hidden5, weights, reuse, 'fc5')
energy = hidden6
return energy