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, return_logit=False):
channels = self.channels
batch_size = tf.shape(inp)[0]
inp = tf.reshape(inp, (batch_size, 64, 64, 1))
if FLAGS.swish_act:
act = swish
else:
act = tf.nn.leaky_relu
if not FLAGS.cclass:
label = None
weights = weights.copy()
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)
h1 = smart_conv_block(inp, weights, reuse, 'c1_pre', use_stride=False, activation=act)
h2 = smart_conv_block(h1, weights, reuse, 'c1', use_stride=True, downsample=True, label=label, extra_bias=True, activation=act)
h3 = smart_conv_block(h2, weights, reuse, 'c2', use_stride=True, downsample=True, label=label, extra_bias=True, activation=act)
h4 = smart_conv_block(h3, weights, reuse, 'c3', use_stride=True, downsample=True, label=label, use_scale=True, extra_bias=True, activation=act)
h5 = smart_conv_block(h4, weights, reuse, 'c4', use_stride=True, downsample=True, label=label, extra_bias=True, activation=act)
hidden6 = tf.reshape(h5, (tf.shape(h5)[0], -1))
hidden7 = act(smart_fc_block(hidden6, weights, reuse, 'fc_dense'))
energy = smart_fc_block(hidden7, weights, reuse, 'fc5')
if return_logit:
return hidden7
else:
return energy