Пример #1
0
def run_training():
    initial_steps=0
    max_steps=30000
    train_clip_path="./val_training_samples.txt"  # turn-tap是专门对提议进行回归的,它的提议采用的clip pyramid的形式,也就是人为首先预设出来很多proposal
    background_path="./background_samples.txt"
    train_featmap_dir="./path_to_features_val/"  # turn-tap使用的是denseflow特征
    test_featmap_dir="./path_to_features_test/"
    test_clip_path="./test_swin.txt"   # 间隔为16帧,时序窗口金字塔分别由{1,2,4,8,16,32}个units组成,共408013个clips

    test_video_length_info={}   # 测试视频时长信息{'视频名':时长}
    with open("./thumos14_video_length_test.txt") as f:
        for l in f:
            test_video_length_info[l.rstrip().split(" ")[0]]=int(l.rstrip().split(" ")[2])  # 获取视频时长(以帧为单位)
	
    train_video_length_info={}
    with open("./thumos14_video_length_val.txt") as f:
        for l in f:
            train_video_length_info[l.rstrip().split(" ")[0]]=int(l.rstrip().split(" ")[2])

    # 初始化模型获取数据集加载器
    model=turn_model.TURN_Model(batch_size,
				train_video_length_info,
				ctx_num,
				unit_feature_size,
				unit_size,
                                lambda_reg,
				lr,
				train_clip_path,
				background_path,
				test_clip_path,
				train_featmap_dir,
				test_featmap_dir)

    with tf.Graph().as_default():	
Пример #2
0
def training():
    initial_steps = 0
    max_steps = 20000

    model = turn_model.TURN_Model()

    with tf.Graph().as_default():

        loss_cls_reg, vs_train_op, vs_eval_op, loss_reg = model.construct_model()
        tf.summary.scalar('loss', loss_cls_reg)
        # 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.global_variables_initializer()
        sess.run(init)
        saver = tf.train.Saver()
        # merged = tf.summary.merge_all()
        # writer = tf.summary.FileWriter("logs/", sess.graph)

        start_time = time.time()
        for step in xrange(max_steps):
            feed_dict = model.fill_feed_dict_train_reg()
            _, loss_v, loss_reg_v = sess.run([vs_train_op, loss_cls_reg, loss_reg], feed_dict=feed_dict)

            if step % 50 == 0:
                duration = time.time() - start_time
                start_time = time.time()
                pt,epoch,train_set_length=model.train_set.get_training_info()
                # rs = sess.run(merged)
                # writer.add_summary(rs, step)
                # Print status to stdout.
                print('Step %d (%d/%d) Epoch %d  total loss = %.2f, regression loss = %.2f(%.3f sec)' % (
                    step, pt,train_set_length,epoch,loss_v, loss_reg_v, duration))
            if step % 1000 == 0:
                probs = []
                labels = []
                pred = []
                for i in range(1000):
                # for i in range(model.val_set):
                    movie_name, gt_start, gt_end, clip_start, clip_end, feat,unit_duration = model.val_set.get_sample(i)
                    feed_dict = {model.visual_featmap_ph_test: feat}
                    outputs = sess.run(vs_eval_op, feed_dict=feed_dict)
                    pred_start, pred_end, action_score = postprocess(clip_start, clip_end, outputs,unit_duration)
                    # print(movie_name, gt_start, gt_end, pred_start, pred_end, action_score)
                    if gt_start == gt_end == 0:
                        label = 0
                    else:
                        label = 1
                    if action_score > 0.5:
                        pred.append(1)
                    else:
                        pred.append(0)
                    probs.append(action_score)
                    labels.append(label)
                # print(pred,probs,labels)
                print("Accuracy", accuracy_score(y_pred=pred, y_true=labels))
                print("Loss", log_loss(y_pred=probs, y_true=labels))
        saver.save(sess, os.path.join(ActivityNet.MODEL_DIR, 'turn_activity_net.model'))
Пример #3
0
def run_training():
    initial_steps = 0
    max_steps = 30000
    train_clip_path = "./val_training_samples.txt"
    background_path = "./background_samples.txt"
    train_featmap_dir = "./path_to_features_val/"
    test_featmap_dir = "./path_to_features_test/"
    test_clip_path = "./test_swin.txt"
    test_video_length_info = {}
    with open("./thumos14_video_length_test.txt") as f:
        for l in f:
            test_video_length_info[l.rstrip().split(" ")[0]] = int(
                l.rstrip().split(" ")[2])
    train_video_length_info = {}
    with open("./thumos14_video_length_val.txt") as f:
        for l in f:
            train_video_length_info[l.rstrip().split(" ")[0]] = int(
                l.rstrip().split(" ")[2])

    model = turn_model.TURN_Model(batch_size, train_video_length_info, ctx_num,
                                  unit_feature_size, unit_size, lambda_reg, lr,
                                  train_clip_path, background_path,
                                  test_clip_path, train_featmap_dir,
                                  test_featmap_dir)

    with tf.Graph().as_default():

        loss_cls_reg, vs_train_op, vs_eval_op, 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 xrange(max_steps):
            start_time = time.time()
            feed_dict = model.fill_feed_dict_train_reg()

            _, loss_v, loss_reg_v = sess.run(
                [vs_train_op, loss_cls_reg, loss_reg], feed_dict=feed_dict)
            duration = time.time() - start_time

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

            if (step + 1) % test_steps == 0:
                print "Start to test:-----------------\n"
                do_eval_slidingclips(sess, vs_eval_op, model,
                                     test_video_length_info, step + 1)
Пример #4
0
def testing():
    model = turn_model.TURN_Model()

    with tf.Graph().as_default():
        sess = tf.Session()

        # First let's load meta graph and restore weights
        # saver = tf.train.import_meta_graph(os.path.join(THUMOS14.MODEL_DIR,'turn_tap_model.meta'))
        loss_cls_reg, vs_train_op, vs_eval_op, loss_reg = model.construct_model(test=True)
        init = tf.global_variables_initializer()
        sess.run(init)
        saver = tf.train.Saver()
        saver.restore(sess, os.path.join(ActivityNet.MODEL_DIR, 'turn_tap_model'))
        # utils.show_tensor(os.path.join(ActivityNet.MODEL_DIR, 'turn_tap_model'))

        result = {}
        probs = []
        labels = []
        pred = []
        for i in range(len(model.test_set.samples)):
        # for i in range(50):
            movie_name, gt_start, gt_end, clip_start, clip_end, feat,unit_duration = model.test_set.get_sample(i)
            feed_dict = {
                model.visual_featmap_ph_test: feat
            }
            outputs = sess.run(vs_eval_op, feed_dict=feed_dict)
            pred_start, pred_end, action_score = postprocess(clip_start, clip_end, outputs,unit_duration)
            # print(movie_name,gt_start,gt_end,pred_start,pred_end,action_score)
            _list = result.get(movie_name, [])
            _list.append((pred_start, pred_end, action_score))
            result[movie_name] = _list
            if gt_start == gt_end == 0:
                label = 0
            else:
                label = 1
            if action_score > 0.5:
                pred.append(1)
            else:
                pred.append(0)
            if action_score == 0:
                action_score = 1e-8
            elif action_score == 1:
                action_score = 0.9999
            probs.append(action_score)
            labels.append(label)

        # print(pred,probs,labels)
        print("Accuracy", accuracy_score(y_pred=pred, y_true=labels))
        print("Loss", log_loss(y_pred=probs, y_true=labels))
Пример #5
0
def training():
    initial_steps=0
    max_steps=10000

    model=turn_model.TURN_Model()
    print(model.init_placeholder())

    with tf.Graph().as_default():

        loss_cls_reg,vs_train_op,vs_eval_op, 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.global_variables_initializer()
        sess.run(init)
        saver = tf.train.Saver()
        start_time = time.time()
        for step in xrange(max_steps):

            feed_dict = model.fill_feed_dict_train_reg()
            _, loss_v, loss_reg_v = sess.run([vs_train_op,loss_cls_reg, loss_reg], feed_dict=feed_dict)

            if step % 50 == 0:
                duration = time.time() - start_time
                # Print status to stdout.
                print('Step %d: total loss = %.2f, regression loss = %.2f(%.3f sec)' % (step, loss_v, loss_reg_v, duration))
                start_time = time.time()
            if step %1000==0:
                for i in range(15,25):
                    movie_name, gt_start, gt_end, clip_start, clip_end, feat = model.test_set.get_sample(i)
                    feed_dict = {
                        model.visual_featmap_ph_test: feat
                    }
                    outputs = sess.run(vs_eval_op, feed_dict=feed_dict)
                    pred_start, pred_end, action_score = output_process(clip_start, clip_end, outputs)
                    print(movie_name, gt_start, gt_end, pred_start, pred_end, action_score)