Exemplo n.º 1
0
im_batch = tf.placeholder(tf.float32, [1, None, None, 3])
bbox_batch = tf.placeholder(tf.float32, [None, 5])
spatial_batch = tf.placeholder(tf.float32, [None, 5])
text_seq_batch = tf.placeholder(tf.int32, [T, None])

scores = visgeno_attention_model.visgeno_attbilstm_net(im_batch, bbox_batch,
                                                       spatial_batch,
                                                       text_seq_batch,
                                                       num_vocab, embed_dim,
                                                       lstm_dim, False, False)

np.random.seed(3)
reader = DataReader(imdb_file,
                    vocab_file,
                    im_mean,
                    shuffle=False,
                    max_bbox_num=10000,
                    max_rel_num=10000)

################################################################################
# Snapshot and log
################################################################################

# Snapshot saver
snapshot_saver = tf.train.Saver()

# Start Session
sess = tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions(
    allow_growth=True)))

# Run Initialization operations
                             processed_W[l_name])
        assign_B = tf.assign(tf.get_variable(l_name + '/biases'),
                             processed_B[l_name])
        init_ops += [assign_W, assign_B]
processed_params.close()

# Initialize word embedding matrix
embedding_mat_val = np.load(wordembed_params)
with tf.variable_scope('lstm', reuse=True):
    embedding_mat = tf.get_variable("embedding_mat", [num_vocab, embed_dim])
    init_we = tf.assign(embedding_mat, embedding_mat_val)

init_ops += [init_we]

# Load data
reader = DataReader(imdb_file, vocab_file, im_mean)

################################################################################
# Snapshot and log
################################################################################

# Snapshot saver
snapshot_saver = tf.train.Saver()

# Log writer
if not os.path.isdir(log_dir):
    os.mkdir(log_dir)
log_writer = tf.summary.FileWriter(log_dir, tf.get_default_graph())
loss_cls_ph = tf.placeholder(tf.float32, [])
lr_ph = tf.placeholder(tf.float32, [])
scores_ph = tf.placeholder(tf.float32, None)