示例#1
0
def run_training():
    initial_steps = 0
    max_steps = 10000
    batch_size = 56
    exp_info = "original"

    train_csv_path = "../TACoS/train_clip-sentvec.pkl"
    test_csv_path = "../TACoS/test_clip-sentvec.pkl"
    test_feature_dir = "../TACoS/Interval128_256_overlap0.8_c3d_fc6/"
    train_feature_dir = "../TACoS/Interval64_128_256_512_overlap0.8_c3d_fc6/"

    cwd = os.getcwd()
    save_model_folder = os.path.join(cwd, "trained_model", exp_info)
    if not os.path.isdir(save_model_folder): os.mkdir(save_model_folder)

    model = ctrl_model.CTRL_Model(batch_size, train_csv_path, test_csv_path,
                                  test_feature_dir, train_feature_dir)
    test_result_output = open("ctrl_test_results.txt", "w")
    with tf.Graph().as_default():

        loss_align_reg, vs_train_op, vs_eval_op, offset_pred, loss_reg = model.construct_model(
        )
        # Create a session for running Ops on the Graph.
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.2)
        sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        # Run the Op to initialize the variables.
        init = tf.initialize_all_variables()
        sess.run(init)
        saver = tf.train.Saver()
        print("Start to test:-----------------\n")
        for step in xrange(max_steps):
            start_time = time.time()
            feed_dict = model.fill_feed_dict_train_reg()
            _, loss_value, offset_pred_v, loss_reg_v = sess.run(
                [vs_train_op, loss_align_reg, offset_pred, loss_reg],
                feed_dict=feed_dict)
            duration = time.time() - start_time

            if step % 200 == 0:
                # Print status to stdout.
                print('Step %d: loss = %.3f (%.3f sec)' %
                      (step, loss_value, duration))

            if (step + 1) % 1000 == 0:  #2000
                saver.save(sess,
                           save_model_folder + "iter_{}.ckpt".format(step))
                print("Start to test:-----------------\n")
                movie_length_info = pickle.load(
                    open("./video_allframes_info.pkl"))
                do_eval_slidingclips(sess, vs_eval_op, model,
                                     movie_length_info, step + 1,
                                     test_result_output)
示例#2
0
文件: main.py 项目: Enosh-Wang/TALL
def run_training():
    initial_steps = 0
    max_steps = 20000
    batch_size = 56
    train_csv_path = "./exp_data/TACoS/train_clip-sentvec.pkl"
    test_csv_path = "./exp_data/TACoS/test_clip-sentvec.pkl"
    test_feature_dir = "/home/share/TACoS/Interval128_256_overlap0.8_c3d_fc6/"
    train_feature_dir = "/home/share/TACoS/Interval64_128_256_512_overlap0.8_c3d_fc6/"

    model = ctrl_model.CTRL_Model(batch_size, train_csv_path, test_csv_path,
                                  test_feature_dir, train_feature_dir)
    test_result_output = open("ctrl_test_results.txt", "w")
    with tf.Graph().as_default():

        loss_align_reg, vs_train_op, vs_eval_op, offset_pred, loss_reg = model.construct_model(
        )
        # Create a session for running Ops on the Graph.
        gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.2)
        sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        # Run the Op to initialize the variables.
        init = tf.initialize_all_variables()
        sess.run(init)
        for step in range(max_steps):
            start_time = time.time()
            feed_dict = model.fill_feed_dict_train_reg()
            _, loss_value, offset_pred_v, loss_reg_v = sess.run(
                [vs_train_op, loss_align_reg, offset_pred, loss_reg],
                feed_dict=feed_dict)
            duration = time.time() - start_time

            if step % 5 == 0:
                # Print status to stdout.
                print(('Step %d: loss = %.3f (%.3f sec)' %
                       (step, loss_value, duration)))

            if (step + 1) % 2000 == 0:
                print("Start to test:-----------------\n")
                movie_length_info = pickle.load(open(
                    "./video_allframes_info.pkl", 'rb'),
                                                encoding='iso-8859-1')
                do_eval_slidingclips(sess, vs_eval_op, model,
                                     movie_length_info, step + 1,
                                     test_result_output)
示例#3
0
def run_evl():
    print('Runing evaluation')
    exp = 'test_video_iter9999'
    batch_size = 56
    train_csv_path = "../TACoS/TACoS/train_clip-sentvec.pkl"
    test_csv_path = "../TACoS/TACoS/test_clip-sentvec.pkl"
    test_feature_dir = "../TACoS/Interval128_256_overlap0.8_c3d_fc6/"
    train_feature_dir = "../TACoS/Interval64_128_256_512_overlap0.8_c3d_fc6/"

    model = ctrl_model.CTRL_Model(batch_size, train_csv_path, test_csv_path,
                                  test_feature_dir, train_feature_dir)
    test_result_output = open("ctrl_test_results_" + exp + ".txt", "ab")
    with tf.Graph().as_default():
        loss_align_reg, vs_train_op, vs_eval_op, offset_pred, loss_reg = model.construct_model(
        )
        sess = tf.Session()
        saver = tf.train.Saver()
        saver.restore(sess, "trained_model/iter_1999.ckpt")
        print("Start to test:-----------------\n")
        movie_length_info = pickle.load(open("./video_allframes_info.pkl"))
        # do_eval_slidingclips(sess, vs_eval_op, model, movie_length_info, 1999 + 1, test_result_output)
        do_eval_slidingclips(sess, vs_eval_op, model, movie_length_info,
                             1999 + 1, test_result_output)
示例#4
0
文件: location.py 项目: ME495/service
import requests, json
import numpy as np
import tensorflow as tf
import pickle
import ctrl_model
import os
import cv2
import json

os.environ["CUDA_VISIBLE_DEVICES"] = "0"
model_name = './ckpt/TALL_c3d.ckpt-12000'
video_dir = '/data02/chengjian19/videos/'

app = Flask(__name__)

model = ctrl_model.CTRL_Model()
loss_align_reg, vs_train_op, vs_eval_op, offset_pred, loss_reg = model.construct_model(
)
saver = tf.train.Saver()
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))
sess.run(tf.global_variables_initializer())
saver.restore(sess, model_name)


def get_visual_featmap(start_center, end_center, feature_center, feature_list):
    feature_pre = feature_center[:]
    feature_after = feature_center[:]
    start_pre, start_after = 0., 100000000.
    for clip_name, feature in feature_list:
        start = float(clip_name.split("_")[0])
        end = float(clip_name.split("_")[1])