snapshot = 5000
snapshot_file = './exp-referit/tfmodel/referit_fc8_det_iter_%d.tfmodel'

################################################################################
# The model
################################################################################

# Inputs
text_seq_batch = tf.placeholder(tf.int32, [T, N])
imcrop_batch = tf.placeholder(tf.float32, [N, 224, 224, 3])
spatial_batch = tf.placeholder(tf.float32, [N, 8])
label_batch = tf.placeholder(tf.float32, [N, 1])

# Outputs
scores = segmodel.text_objseg_region(text_seq_batch, imcrop_batch,
    spatial_batch, num_vocab, embed_dim, lstm_dim, mlp_hidden_dims,
    vgg_dropout=vgg_dropout, mlp_dropout=mlp_dropout)

################################################################################
# Collect trainable variables, regularized variables and learning rates
################################################################################

# Only train the fc layers of convnet and keep conv layers fixed
if fix_convnet:
    train_var_list = [var for var in tf.trainable_variables()
                      if not var.name.startswith('vgg_local/')]
else:
    train_var_list = [var for var in tf.trainable_variables()
                      if not var.name.startswith('vgg_local/conv')]
print('Collecting variables to train:')
for var in train_var_list: print('\t%s' % var.name)
Beispiel #2
0
embed_dim = 1000
lstm_dim = 1000
mlp_hidden_dims = 500

################################################################################
# detection network
################################################################################

# Inputs
text_seq_batch = tf.placeholder(tf.int32, [T, N])  # one batch per sentence
imcrop_batch = tf.placeholder(tf.float32, [N, 224, 224, 3])
spatial_batch = tf.placeholder(tf.float32, [N, 8])

# Language feature (LSTM hidden state)
_ = segmodel.text_objseg_region(text_seq_batch, imcrop_batch,
    spatial_batch, num_vocab, embed_dim, lstm_dim, mlp_hidden_dims,
    vgg_dropout=False, mlp_dropout=False)

# Load pretrained detection model and fetch weights
snapshot_loader = tf.train.Saver()
with tf.Session() as sess:
    snapshot_loader.restore(sess, det_model)
    variable_dict = {var.name:var.eval(session=sess) for var in tf.all_variables()}

################################################################################
# low resolution segmentation network
################################################################################

# Clear the graph
tf.python.ops.reset_default_graph()