Exemple #1
0
def run_mlm():
    global LAMBDA, b, MU, WEIGHTS, INCREMENT
    timer = Timer('main')
    timer.start()
    try:
        for j in range(0, int(1 / INCREMENT)):
            k = 1
            for i in range(0, int(1 / INCREMENT)):
                run(k=k, b=b, lam=LAMBDA, mu=MU, weights=WEIGHTS)
                baseline = eval.full_eval(QRELS_FILE, RANKING_FILE)
                mlm = eval.full_eval(QRELS_FILE, MLM_FILE)
                with open('data/results.txt', 'a') as rfile:
                    rfile.write('SCR   P@10  (M)AP  (M)RR using parameters '
                                'lambda={0:05.3f}, weights={1:05.3f}\n'.format(
                                    LAMBDA, WEIGHTS))
                    rfile.write(
                        'BLN  {0:05.3f}  {1:05.3f}  {2:05.3f}\n'.format(
                            baseline['p10'], baseline['ap'], baseline['rr']))
                    rfile.write(
                        'MLM  {0:05.3f}  {1:05.3f}  {2:05.3f}\n'.format(
                            mlm['p10'], mlm['ap'], mlm['rr']))
                LAMBDA += INCREMENT
                for w in WEIGHTS:
                    w += INCREMENT
    except Exception as e:
        dump_args([LAMBDA, b])
        print('There was an error \n {}'.format(e))
    timer.stop()
    print(timer.total_running_time_long)
Exemple #2
0
    for i in range(int(1/increment)):
        SIM["similarity"]["default"]["k1"] = 1
        for j in range(int(1/increment)):
            loop_vars = get_vars(SIM)
            print('Running loop no. {}...'.format(loop_no))
            file = 'data/bmo/results_b_{0:04.2f}_k_{1:04.2f}_.txt'.format(loop_vars[1], loop_vars[0])
            if exists(file):
                print('Results for b={0:04.2f}, k={1:04.2f} already exist'.format(loop_vars[1], loop_vars[0]))
            else:
                run_query(file, es)
            SIM["similarity"]["default"]["k1"] += increment
            change_model(SIM, es)
            loop_no += 1
        SIM["similarity"]["default"]["b"] += increment
        change_model(SIM, es)

    for i in os.listdir('data/BMO/'):
        with open('data/bmo/evaluations.txt', 'a') as f:
            cur_file = 'data/bmo/{}'.format(i)
            print('Evaluating {}...'.format(cur_file))
            if cur_file.startswith('data/bmo/results'):
                feval = eval.full_eval(QRELS_FILE, cur_file)
                fvars = i.split('_')
                f.write('\tP@10  (M)AP  (M)RR using parameters b={0:04.2f}, k={1:04.2f}\n'.format(float(fvars[2]),
                                                                                                  float(fvars[4])))
                f.write('\t{0:05.3f}  {1:05.3f}  {2:05.3f}\n'.format(feval['p10'], feval['ap'], feval['rr']))
            else:
                print('Invalid file, skipping...')
    change_model(DEFAULT_SIM, es)  # Resets the search model
Exemple #3
0
def singleprocess_run():
    run(k=k, b=b, lam=LAMBDA, mu=MU)
    baseline = eval.full_eval(QRELS_FILE, RANKING_FILE)
    mlm = eval.full_eval(QRELS_FILE, MLM_FILE)
    bm = eval.full_eval(QRELS_FILE, BM_FILE)
    return [baseline, mlm, bm]
Exemple #4
0
def main():
    gpu_config = tf.ConfigProto()
    gpu_config.gpu_options.allow_growth = True
    if flags.data_source == 'video_sub': flags.dim_mcb = 4096
    with tf.Session(config=gpu_config) as sess:
        _inputs = {
            'query':
            tf.placeholder(dtype=tf.float32,
                           shape=[None, flags.dim_text],
                           name='query_input'),
            'answer':
            tf.placeholder(dtype=tf.float32,
                           shape=[None, 5, flags.dim_text],
                           name='answer_input'),
            'story':
            tf.placeholder(dtype=tf.float32,
                           shape=[None, flags.dim_mcb],
                           name='story_input'),
            'cor_idx':
            tf.placeholder(dtype=tf.int64, shape=[None], name='cor_idx_input'),
            'rgb':
            tf.placeholder(dtype=tf.float32, shape=[None, flags.dim_rgb]),
            'sub':
            tf.placeholder(dtype=tf.float32, shape=[None, flags.dim_sub])
        }
        if FLAGS.video_features == True:
            _inputs.pop("story", None)
        else:
            _inputs.pop("rgb", None)
            _inputs.pop("sub", None)

        if FLAGS.video_features == True:
            model = ltm_video_model(flags=flags, inputs=_inputs)
        else:
            model = ltm_model(flags=flags, inputs=_inputs)
        model.build_model()

        model_vars = tf.contrib.framework.get_model_variables()
        tf.contrib.slim.model_analyzer.analyze_vars(model_vars,
                                                    print_info=True)
        saved_op = {}
        for var in tf.trainable_variables():
            print(var.name)
            saved_op[var.name] = var

        train_queue = LTM_Queue(story_filename=STORY_FILE,
                                qa_filelist=QA_TRAIN,
                                capacity=30,
                                batch_size=32,
                                num_threads=20)

        val_queue = LTM_Queue(story_filename=STORY_FILE,
                              qa_filelist=QA_VAL,
                              capacity=30,
                              batch_size=32,
                              num_threads=10)

        train_queue.start_threads()
        val_queue.start_threads()

        merge_op, train_writer, val_writer = build_summary_ops(
            model, flags, sess)
        checkpoint_op, checkpoint_dir = build_checkpoint_ops(flags)
        tf.global_variables_initializer().run()

        best_accuracy = 0.0
        for step in xrange(FLAGS.max_steps):
            ts = time()
            queue_inputs = train_queue.get_inputs()
            feed = {}
            for key, val in _inputs.iteritems():
                try:
                    feed[_inputs[key]] = queue_inputs[key + '_rep']
                except:
                    feed[_inputs[key]] = queue_inputs[key]
            loss, _ = sess.run([model.loss, model.train_op], feed_dict=feed)
            loss_mean = np.mean(loss)

            print('| Step %07d | Loss %.3f | Time spent %.3f |' %
                  (step, loss_mean, time() - ts),
                  end='\r')
            if step == 0: continue
            if step % SUMMARY_STEP == 0:
                summary = sess.run(merge_op, feed_dict=feed)
                train_writer.add_summary(summary, step)

            if step % VAL_STEP == 0:
                queue_inputs = val_queue.get_inputs()
                feed = {}
                for key, val in _inputs.iteritems():
                    try:
                        feed[_inputs[key]] = queue_inputs[key + '_rep']
                    except:
                        feed[_inputs[key]] = queue_inputs[key]
                loss = sess.run(model.loss, feed_dict=feed)
                loss_mean = np.mean(loss)

                summary = sess.run(merge_op, feed_dict=feed)
                val_writer.add_summary(summary, step)

            if step % FULL_EVAL_STEP == 0 and step >= 900:
                num_val_examples = {
                    'VideoSubInception': 886,
                    'VideoSubResnet': 886,
                    'video_sub': 886,
                    'sub': 1958,
                    "sub_part": 1958,
                    'dvs': 282,
                    'dvs_pe': 282,
                    'script': 976,
                    'plot': 1958,
                    'sub_fasttext': 1958
                }
                accuracy = full_eval(step, _inputs, model, sess, STORY_FILE,
                                     QA_VAL,
                                     num_val_examples[FLAGS.data_source])
                best_accuracy = max([best_accuracy, accuracy])
                if accuracy >= FLAGS.save_threshold:
                    print("Saving checkpoint| Step {} | Accuracy : {} ".format(
                        step, accuracy))
                    save_checkpoint(sess, checkpoint_dir, checkpoint_op, step)
    print("Best Accuracy : {}".format(best_accuracy))