Пример #1
0
def main():
    # Avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'

    # --- Parse arguments from JSON file ---
    hp, evaluation, run, env, design = parse_arguments()
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env)

    # --- Start Streaming from Video ---
    cap = cv2.VideoCapture(env.root_sequences + '/' + sys.argv[1] + '.mp4')
    ret, frame = cap.read()
    if (not ret):
        print "Error opening video sequence"

    # --- Save Video (Optional) ---
    if run.save_video:
        vid_write = cv2.VideoWriter(
            env.root_sequences + '/' + sys.argv[1] + '_out.avi',
            cv2.VideoWriter_fourcc(*'MJPG'), 25,
            (frame.shape[1], frame.shape[0]), True)

    # --- Define Initial Bounding Box ---
    BB = click_and_crop(frame, design.window_name)

    cv2.namedWindow(design.window_name)
    cv2.startWindowThread()
    cv2.setMouseCallback(design.window_name, BB.callback)

    cv2.imshow(design.window_name, frame)
    cv2.waitKey(0)

    while True:
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # ----- Define Initial Bounding Box Params & Template -----
    pos_x = int((BB.refPt[0][0] + BB.refPt[1][0]) / 2)  # Template Center
    pos_y = int((BB.refPt[0][1] + BB.refPt[1][1]) / 2)  # Template Center
    target_w = int(abs(BB.refPt[1][0] - BB.refPt[0][0]))  # Template Width / 2
    target_h = int(abs(BB.refPt[1][1] - BB.refPt[0][1]))  # Template Height / 2

    # ----- Beging Tracking -----
    tracker(hp, run, design, pos_x, pos_y, target_w, target_h, final_score_sz,
            templates_z, scores, cap, vid_write, frame)

    cap.release()
    cv2.destroyAllWindows()

    if run.save_video:
        vid_write.release()
Пример #2
0
def evaluate():
	# avoid printing TF debugging information
	os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
	# TODO: allow parameters from command line or leave everything in json files?
	hp, evaluation, run, env, design = parse_arguments()
	# Set size for use with tf.image.resize_images with align_corners=True.
	# For example,
	#   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
	# instead of
	# [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
	final_score_sz = hp.response_up * (design.score_sz - 1) + 1
	# build TF graph once for all
	gt, frame_name_list, _, _ = _init_video(env, evaluation, evaluation.video)
	
	frame_sz = [i for i in cv2.imread(frame_name_list[0]).shape]
	
	siamNet = siam.Siamese(batch_size = 1);
	image, z_crops, x_crops, templates_z, scores, loss, _, distance_to_gt, summary, templates_x, max_pos_x, max_pos_y = siamNet.build_tracking_graph_train(final_score_sz, design, env, hp, frame_sz)


	
	pos_x, pos_y, target_w, target_h = region_to_bbox(gt[evaluation.start_frame])
	bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y, target_w, target_h, final_score_sz,
		                    image, templates_z, scores, evaluation.start_frame,  path_ckpt = os.path.join(design.saver_folder, design.path_ckpt), siamNet = siamNet)
	_, precision, precision_auc, iou = _compile_results(gt, bboxes, evaluation.dist_threshold)
	
	print(evaluation.video + \
		  ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
		  ' -- Precision AUC: ' + "%.2f" % precision_auc + \
		  ' -- IOU: ' + "%.2f" % iou + \
		  ' -- Speed: ' + "%.2f" % speed + ' --')
Пример #3
0
def run_SiamFCpytorch(seq, rp, bSaveImage):
    hp, evaluation, run, env, design = parse_arguments()
    #final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    final_score_sz = 265
    siam = SiameseNet(env.root_pretrained, design.net)
    load_net(NET_PATH, siam)
    siam.cuda()

    frame_name_list = seq.s_frames
    init_rect = seq.init_rect
    x, y, width, height = init_rect  # OTB format

    init_bb = Rectangle(x - 1, y - 1, float(width), float(height))
    init_bb = convert_bbox_format(init_bb, 'center-based')

    bboxes, speed = tracker(hp, run, design, frame_name_list, init_bb.x,
                            init_bb.y, init_bb.width, init_bb.height,
                            final_score_sz, siam, evaluation.start_frame)

    trajectory = [
        Rectangle(val[0] + 1, val[1] + 1, val[2], val[3]) for val in bboxes
    ]
    result = dict()
    result['res'] = trajectory
    result['type'] = 'rect'
    result['fps'] = speed
    return result
def main(process, queue, box, video):
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    image, templates_z, scores = siam.build_tracking_graph(final_score_sz, design, env)
    
    # read radio
    # width = 640
    # height = 480
    # process1 = (
    #     ffmpeg
    #     .input('tcp://192.168.1.155:8300',vcodec='h264',r = 24,probesize=32,fflags="nobuffer",flags="low_delay",analyzeduration=1)
    #     .output('pipe:', format='rawvideo',pix_fmt="rgb24")
    #     .run_async(pipe_stdout=True)
    # )
    ## model 
    # model_path = './frozen_inference_graph.pb'
    # odapi = DetectorAPI(path_to_ckpt=model_path)
    # while True :
    # in_bytes = process1.stdout.read(width * height * 3)
    # if not in_bytes :
    #     print ("none")
    # video = (np.frombuffer(in_bytes, np.uint8).reshape([height, width, 3]))
    # video = cv2.cvtColor(video, cv2.COLOR_RGB2BGR)

    # read target from mat
    # box = odapi.processFrame(video)
    box[2] -= box[0]
    box[3] -= box[1]
    box[0] += box[2]/2
    box[1] += box[3]/2
    print ('box', box)
    pos_x, pos_y, target_w, target_h = box[0], box[1], box[2], box[3]
    tracker(hp, run, design, video, pos_x, pos_y, target_w, target_h, final_score_sz,
                            image, templates_z, scores, process, queue)
    print ('done')
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    filename, image, templates_z, scores = siam.build_tracking_graph(final_score_sz, design, env)

    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            images_arr, gt, frame_name_list, frame_sz, n_frames = _init_video(env, evaluation, videos_list[i])
            starts = np.rint(np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                start_frame = int(starts[j])
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_, pos_x, pos_y,
                                                                     target_w, target_h, final_score_sz, filename,
                                                                     image, templates_z, scores, start_frame)
                lengths[idx], precisions[idx], precisions_auc[idx], ious[idx] = compile_results(gt, bboxes, evaluation.dist_threshold)
                print(str(i) + ' -- ' + videos_list[i] + ' -- Precision: ' + "%.2f" % precisions[idx] + ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + ' -- IOU: ' + "%.2f" % ious[idx] + ' -- Speed: ' + "%.2f" % speed[idx] + ' --')
        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print('-- Overall stats (averaged per frame) on ' + str(nv) + ' videos (' + str(tot_frames) + ' frames) --')
        print(' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision + ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc + ' -- IOU: ' + "%.2f" % mean_iou + ' -- Speed: ' + "%.2f" % mean_speed + ' --')

    else:
        images_arr, gt, frame_name_list, _, _ = _init_video(env, evaluation, evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(gt[evaluation.start_frame]) 
      
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y, target_w, target_h, final_score_sz,
                                filename, image, templates_z, scores, evaluation.start_frame)        
                            
        num_frames = np.size(frame_name_list)
        bboxes_final = np.zeros((num_frames,4))

        lk_params = dict( winSize  = (5,5),
                  maxLevel = 2,
                  criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 1, 0.03))

        bboxes_final = np.zeros((num_frames, 4))
        for i in range(1,len(images_arr)-1):
            # Create some random colors
            color = np.random.randint(0,255,(100,3))

            # Take first frame and find corners in it
            #ret, old_frame = cap.read()
            frame = images_arr[i+1]
            old_frame = images_arr[i]
            old_gray = cv2.cvtColor(old_frame, cv2.COLOR_BGR2GRAY)
            p0 = np.zeros((1,1,2), dtype=np.float32)
            bbox_i = bboxes[i]
            c, r, w, h = int(bbox_i[0]), int(bbox_i[1]), int(bbox_i[2]), int(bbox_i[3])
            p0[0,0,0] = c
            p0[0,0,1] = r
            frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            p1, st, err = cv2.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)
            good_new = p1[st==1]
            bboxes_final[i,:] = p1[0][0][0], p1[0][0][1], w, h
            good_old = p0[st==1]   
            for i,(new,old) in enumerate(zip(good_new,good_old)):
                a,b = new.ravel()
                c,d = old.ravel()
            fig = plt.figure(1)
            ax = fig.add_subplot(111)
            r1 = patches.ConnectionPatch((a,b),(c,d),'data','data',arrowstyle="-|>") 
            r2 = patches.Circle((a,b),5,color='r')#((x,y), w, h, linewidth=2, edgecolor='r', fill=False)
            ax.imshow(np.uint8(frame))
            ax.add_patch(r2)
            ax.add_patch(r1)
            plt.ion()
            plt.show()
            plt.pause(0.001)
            plt.clf()
            old_gray = frame_gray.copy()
            p0 = good_new.reshape(-1,1,2)
        _, precision, precision_auc, iou = _compile_results(gt, bboxes_final, evaluation.dist_threshold)
        print(evaluation.video + ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision + ' -- Precision AUC: ' + "%.2f" % precision_auc + ' -- IOU: ' + "%.2f" % iou + ' -- Speed: ' + "%.2f" % speed + ' --')
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # Load hyperparameter (hp), evaluation, run, environment (env) and design parameters from
    # parameters/ directory.
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    filename, image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env)

    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            gt, frame_name_list, frame_sz, n_frames = _init_video(
                env, evaluation, videos_list[i])
            starts = np.rint(
                np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                start_frame = int(starts[j])
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_,
                                             pos_x, pos_y, target_w, target_h,
                                             final_score_sz, filename, image,
                                             templates_z, scores, start_frame)
                lengths[idx], precisions[idx], precisions_auc[idx], ious[
                    idx] = _compile_results(gt_, bboxes,
                                            evaluation.dist_threshold)
                print str(i) + ' -- ' + videos_list[i] + \
                ' -- Precision: ' + "%.2f" % precisions[idx] + \
                ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
                ' -- IOU: ' + "%.2f" % ious[idx] + \
                ' -- Speed: ' + "%.2f" % speed[idx] + ' --'
                print

        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print '-- Overall stats (averaged per frame) on ' + str(
            nv) + ' videos (' + str(tot_frames) + ' frames) --'
        print ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --'
        print

    else:
        gt, frame_name_list, _, _ = _init_video(env, evaluation,
                                                evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(
            gt[evaluation.start_frame])
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y,
                                target_w, target_h, final_score_sz, filename,
                                image, templates_z, scores,
                                evaluation.start_frame)
        _, precision, precision_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)
        print evaluation.video + \
              ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
              ' -- Precision AUC: ' + "%.2f" % precision_auc + \
              ' -- IOU: ' + "%.2f" % iou + \
              ' -- Speed: ' + "%.2f" % speed + ' --'
        print
def main():
    hp, evaluation, run, env, design = parse_arguments()
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    siam = SiameseNet(env.root_pretrained, design.net)
    if torch.cuda.is_available():
        siam = siam.cuda()

    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        video_list = [v for v in os.listdir(dataset_folder) if not v[0] == '.']
        video_list.sort()
        nv = np.size(video_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precision_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            print('video: %d' % (i + 1))
            gt, frame_name_list, frame_sz, n_frame = _init_video(
                env, evaluation, video_list[i])
            starts = np.rint(
                np.linspace(0, n_frame - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                starts_frame = int(starts[j])
                gt_ = gt[starts_frame:, :]
                frame_name_list = frame_name_list[starts_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list,
                                             pos_x, pos_y, target_w, target_h,
                                             final_score_sz, siam,
                                             starts_frame)
                lengths[idx], precisions[idx], precision_auc[idx], ious[
                    idx] = _compile_results(gt_, bboxes,
                                            evaluation.dist_threshold)
                print(str(i) + ' -- ' + video_list[i] + \
                      ' -- Precision: ' + "%.2f" %precisions[idx] + \
                      ' -- Precisions AUC: ' + "%.2f" %precision_auc[idx] + \
                      ' -- IOU: ' + "%.2f" % ious[idx] + \
                      '-- Speed: ' + "%.2f" % speed[idx] + ' --\n')
        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_precision_auc = np.sum(precision_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print(' -- Overall stats (averaged per frame) on ' + str(nv) +
              'videos(' + str(tot_frames) + 'frames) --')
        print(' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" %mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" %mean_iou +\
              ' -- Speed: ' + "%.2f" %mean_speed + '-- \n')
    else:
        gt, frame_name_list, _, _ = _init_video(env, evaluation,
                                                evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(
            gt[evaluation.start_frame])
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y,
                                target_w, target_h, final_score_sz, siam,
                                evaluation.start_frame)
        _, precision, precision_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)
        print(evaluation.video + \
              ' -- precision ' + "(%d px)" %evaluation.dist_threshold + ': ' + "%.2f" % precision +\
              ' -- precision AUC: ' + "%.2f" %precision_auc + \
              ' -- IOU: ' + "%.2f" %iou +\
              '-- Speed: ' + "%.2f" %speed + ' -- \n')
Пример #8
0
def main():
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    siam = SiameseNet(env.root_pretrained, design.net)

    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder) if not v[0] == '.']
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv): # -- Iterate through all videos 
            print('video: %d' % (i + 1))
            gt, frame_name_list, frame_sz, n_frames = _init_video(env, evaluation, videos_list[i])
            starts = np.rint(np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq): # -- Iterate through a single video
                start_frame = int(starts[j])
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                # bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_, pos_x, pos_y,
                #                                                      target_w, target_h, final_score_sz, filename,
                #                                                      image, templates_z, scores, start_frame)
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_, pos_x, pos_y,
                                             target_w, target_h, final_score_sz, siam, start_frame) # -- here is where tracker.py is called 
                lengths[idx], precisions[idx], precisions_auc[idx], ious[idx] = _compile_results(gt_, bboxes, evaluation.dist_threshold)
                print(str(i) + ' -- ' + videos_list[i] + \
                ' -- Precision: ' + "%.2f" % precisions[idx] + \
                ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
                ' -- IOU: ' + "%.2f" % ious[idx] + \
                ' -- Speed: ' + "%.2f" % speed[idx] + ' --\n')

        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print('-- Overall stats (averaged per frame) on ' + str(nv) + ' videos (' + str(tot_frames) + ' frames) --')
        print(' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --\n')

    else:
        gt, frame_name_list, _, _ = _init_video(env, evaluation, evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(gt[evaluation.start_frame])
        # bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y, target_w, target_h, final_score_sz,
        #                         filename, image, templates_z, scores, evaluation.start_frame)
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y, target_w, target_h, final_score_sz,
                                siam, evaluation.start_frame)
        _, precision, precision_auc, iou = _compile_results(gt, bboxes, evaluation.dist_threshold)
        print(evaluation.video + \
              ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
              ' -- Precision AUC: ' + "%.2f" % precision_auc + \
              ' -- IOU: ' + "%.2f" % iou + \
              ' -- Speed: ' + "%.2f" % speed + ' --\n')
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    #由于得到的sorcemap与原图像大小不一致,所以要在这里按比例进行放大以此来得到图像中每个位置对应的score
    #这里的final也就是design中的search_sz
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    filename, image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env, hp)

    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            if os.path.exists(os.path.join('data/result', videos_list[i])):
                continue
            gt, frame_name_list, frame_sz, n_frames, video_folder, equal = _init_video(
                env, evaluation, videos_list[i])
            if not equal:
                print('The .jpg and .xml is not equal in', video_folder)
                continue
            starts = np.rint(
                np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            # for j in range(evaluation.n_subseq):
            for j in range(1):
                start_frame = int(starts[j])
                gt_ = gt[start_frame:]
                frame_name_list_ = frame_name_list[start_frame:]
                # pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                pos_x, pos_y, target_w, target_h = xml_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_,
                                             pos_x, pos_y, target_w, target_h,
                                             final_score_sz, filename, image,
                                             templates_z, scores, start_frame)
                lengths[idx], precisions[idx], precisions_auc[idx], ious[idx] =\
                    _compile_results(gt_, bboxes, evaluation.dist_threshold)

                print str(i) + ' -- ' + videos_list[i] + \
                ' -- Precision: ' + "%.2f" % precisions[idx] + \
                ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
                ' -- IOU: ' + "%.2f" % ious[idx] + \
                ' -- Speed: ' + "%.2f" % speed[idx] + ' --'
                print

                # Draw_Result(bboxes, frame_name_list_, gt_, env)

        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print
        print '-- Overall stats (averaged per frame) on ' + str(
            nv) + ' videos (' + str(tot_frames) + ' frames) --'
        print ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --'
        print

    else:
        gt, frame_name_list, _, _, video_folder, equal = _init_video(
            env, evaluation, evaluation.video)
        if not equal:
            print("The .jpg and .xml is not equal in", video_folder)
            exit(0)
        pos_x, pos_y, target_w, target_h = xml_to_bbox(
            gt[evaluation.start_frame])
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y,
                                target_w, target_h, final_score_sz, filename,
                                image, templates_z, scores,
                                evaluation.start_frame)
        _, precision, precision_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)
        print evaluation.video + \
              ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
              ' -- Precision AUC: ' + "%.2f" % precision_auc + \
              ' -- IOU: ' + "%.2f" % iou + \
              ' -- Speed: ' + "%.2f" % speed + ' --'
        print
def evaluate():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1

    # build the computational graph of Siamese fully-convolutional network
    siamNet = siam.Siamese(batch_size=1)
    # get tensors that will be used during tracking
    image, z_crops, x_crops, templates_z, scores, loss, _, distance_to_gt, summary = siamNet.build_tracking_graph_train(
        final_score_sz, design, env, hp)
    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv)
        precisions = np.zeros(nv)
        precisions_auc = np.zeros(nv)
        ious = np.zeros(nv)
        lengths = np.zeros(nv)
        for i in range(nv):
            gt, frame_name_list, frame_sz, n_frames = _init_video(
                env, evaluation, videos_list[i])

            gt_ = gt[0:, :]
            frame_name_list_ = frame_name_list[0:]
            pos_x, pos_y, target_w, target_h = region_to_bbox(
                gt_[0]
            )  # coordinate of gt is the bottom left point of the bbox
            idx = i
            bboxes, speed[idx] = tracker(hp,
                                         run,
                                         design,
                                         frame_name_list,
                                         pos_x,
                                         pos_y,
                                         target_w,
                                         target_h,
                                         final_score_sz,
                                         image,
                                         templates_z,
                                         scores,
                                         path_ckpt=os.path.join(
                                             design.saver_folder,
                                             design.path_ckpt),
                                         siamNet=siamNet)
            lengths[idx], precisions[idx], precisions_auc[idx], ious[
                idx] = _compile_results(gt_, bboxes, evaluation.dist_threshold)
            print(str(i) + ' -- ' + videos_list[i] + \
            ' -- Precision: ' + "%.2f" % precisions[idx] + \
            ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
            ' -- IOU: ' + "%.2f" % ious[idx] + \
            ' -- Speed: ' + "%.2f" % speed[idx] + ' --')

        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print('-- Overall stats (averaged per frame) on ' + str(nv) +
              ' videos (' + str(tot_frames) + ' frames) --')
        print(' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --')
    #evaluate only one vedio
    else:
        gt, frame_name_list, frame_sz, n_frames = _init_video(
            env, evaluation, evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(gt[0])
        bboxes, speed = tracker(hp,
                                run,
                                design,
                                frame_name_list,
                                pos_x,
                                pos_y,
                                target_w,
                                target_h,
                                final_score_sz,
                                image,
                                templates_z,
                                scores,
                                path_ckpt=os.path.join(design.saver_folder,
                                                       design.path_ckpt),
                                siamNet=siamNet)
        _, precision, precision_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)

        print(evaluation.video + \
           ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
           ' -- Precision AUC: ' + "%.2f" % precision_auc + \
           ' -- IOU: ' + "%.2f" % iou + \
           ' -- Speed: ' + "%.2f" % speed + ' --')
        return precision, precision_auc, iou, speed
Пример #11
0
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments(mode="conv2")
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * design.score_sz
    # build TF graph once for all
    image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env)
    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        # videos_list = videos_list[91:][:] #only use vot 2016
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        success_auc = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            # gt, frame_name_list, frame_sz, n_frames, img_mode = _init_video(env, evaluation, videos_list[i])
            gt, frame_name_list, frame_sz, n_frames, img_mode = _init_video_OTB(
                env, evaluation, videos_list[i])

            starts = np.rint(
                np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                start_frame = int(starts[j])
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_,
                                             pos_x, pos_y, target_w, target_h,
                                             final_score_sz, image,
                                             templates_z, scores, start_frame)
                lengths[idx], precisions[idx], precisions_auc[idx], ious[
                    idx], success_auc[idx] = _compile_results(
                        gt_, bboxes, evaluation.dist_threshold)

                print str(i) + ' -- ' + videos_list[i] + \
                ' -- Precision: ' + "%.2f" % precisions[idx] + \
                ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
                ' -- IOU: ' + "%.2f" % ious[idx] + \
                ' -- Success AUC: ' + "%.2f" % success_auc[idx] + \
                ' -- Speed: ' + "%.2f" % speed[idx] + ' --'
                print

        tot_frames = np.mean(lengths)
        mean_precision = np.mean(precisions)
        mean_precision_auc = np.mean(precisions_auc)
        mean_iou = np.mean(ious)
        mean_success_auc = np.mean(success_auc)
        mean_speed = np.mean(speed)

        print 'data set ' + evaluation.dataset + ' z_lr %f scale_step %f scale_penalty %f scale_lr %f window_influence %f' % (
            hp.z_lr, hp.scale_step, hp.scale_penalty, hp.scale_lr,
            hp.window_influence)
        print '-- Overall stats (averaged per frame) on ' + str(
            nv) + ' videos (' + str(tot_frames) + ' frames) --'
        print ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Success AUC: ' + "%.2f" % mean_success_auc +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --'
        print

        with open('log_test.txt', 'a+') as f:
            f.write(time.asctime(time.localtime(time.time())) + '\r\n')
            f.write(
                'data set ' + evaluation.dataset +
                ' z_lr %f scale_step %f scale_penalty %f scale_lr %f window_influence %f \r\n'
                % (hp.z_lr, hp.scale_step, hp.scale_penalty, hp.scale_lr,
                   hp.window_influence))
            f.write('-- Overall stats (averaged per frame) on ' + str(nv) +
                    ' videos (' + str(tot_frames) + ' frames) --\r\n')
            f.write(' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision + \
                    ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc + \
                    ' -- IOU: ' + "%.2f" % mean_iou + \
                    ' -- AUC: ' + "%.3f" % mean_success_auc + \
                    ' -- Speed: ' + "%.2f" % mean_speed + ' --\r\n')
            f.write('\r\n')

    else:
        gt, frame_name_list, _, _ = _init_video(env, evaluation,
                                                evaluation.video)
        pos_x, pos_y, target_w, target_h = region_to_bbox(
            gt[evaluation.start_frame])
        bboxes, speed = tracker(hp, run, design, frame_name_list, pos_x, pos_y,
                                target_w, target_h, final_score_sz, filename,
                                image, templates_z, scores,
                                evaluation.start_frame)
        _, precision, precision_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)
        print evaluation.video + \
              ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
              ' -- Precision AUC: ' + "%.2f" % precision_auc + \
              ' -- IOU: ' + "%.2f" % iou + \
              ' -- Speed: ' + "%.2f" % speed + ' --'
        print
Пример #12
0
def runSiamfc(folderPath, fourcc, testWidth, testHeight, graph, scfg):
    print('Running Siamfc: ' + folderPath)
    frame_name_list = _init_video(folderPath)
    hp, evaluation, run, env, design = parse_arguments()
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    fp = open(os.path.join(folderPath, 'YoloBoxes.txt'))
    filename, image, templates_z, scores, graph1, scfg1 = siam.build_tracking_graph(
        final_score_sz, design, env)
    finalImages = []
    Allbboxes = []
    SiamfcVid = cv2.VideoWriter(join(folderPath, 'SiamfcVid.avi'), fourcc, 10,
                                (testWidth, testHeight))
    f = open(folderPath + "/SiamfcBoxes.txt", "w+")
    nucAngles = open(os.path.join(folderPath, "nuclearAngles.txt"), "r")
    print(refreshRate)
    for i in range(len(frame_name_list)):
        line = fp.readline()
        finalImages = []
        if (line == '\n'):
            continue
        elif (i % refreshRate == 0):
            boxes = line[:-1].split(':')
            boxNr = 0
            for j in Allbboxes:
                #label = j.label
                #pos_x = j.positions[len(j.positions)-1][0]
                #pos_y = j.positions[len(j.positions)-1][1]
                #target_w = j.positions[len(j.positions)-1][2]
                #target_h = j.positions[len(j.positions)-1][3]
                #bboxes, speed, finalImages = tracker(graph1, scfg1, hp, run, design, frame_name_list[i:i+refreshRate-1], pos_x, pos_y, target_w, target_h, final_score_sz,
                #                                    filename, image, templates_z, scores, label,0,colors[boxNr%len(colors)],0,refreshRate-1, finalImages, 0)
                #j.positions = np.concatenate((j.positions,bboxes),0)
                j.padafter(refreshRate)
            for j in boxes:
                box = j.split(',')
                label = box[0]
                box = map(int, box[1:])
                print(
                    'In folder %s Image %d has a box at %d,%d,%d,%d with label %s'
                    % (folderPath, i, box[0], box[1], box[2], box[3], label))
                pos_x = box[0]
                pos_y = box[1]
                target_w = box[2]
                target_h = box[3]
                print('Pos_x: %d, Pos_y:%d, width:%d, height:%d' %
                      (pos_x, pos_y, target_w, target_h))
                bboxes, speed, finalImages = tracker(
                    graph1, scfg1, hp, run, design,
                    frame_name_list[i:i + refreshRate - 1], pos_x, pos_y,
                    target_w, target_h, final_score_sz, filename, image,
                    templates_z, scores, label, 0, colors[boxNr % len(colors)],
                    0, refreshRate - 1, finalImages, 0)
                newBox = sfc_bbox(colors[boxNr % len(colors)], label, bboxes,
                                  0)
                newBox.padfront(i)
                Allbboxes.append(newBox)
                boxNr = boxNr + 1
                print(bboxes)
            fname = i
            probs = [0] * len(Allbboxes)
            #print(Allbboxes)
            if (liveFeed):
                try:
                    oldFolderPath = folderPath.split('_')
                    oldFolderPath[2] = str(int(oldFolderPath[2]) - 1)
                    underscore = '_'
                    oldFolderPath = underscore.join(oldFolderPath)
                except:
                    print("Could not load old probabilies")
                    oldFolderPath = ""
            else:
                oldFolderPath = ""
            if (os.path.isfile(oldFolderPath + "/SiamfcBoxes.txt")):
                print('Extracting old probs')
                probs = getOldProbs(oldFolderPath, Allbboxes,
                                    [(item.split(','))[0] for item in boxes])
                print(probs)
            for j in range(len(finalImages)):
                #print(probs)
                angle = int(nucAngles.readline())
                calcProbs(finalImages[j], angle, Allbboxes, i + j, f)
                cv2.circle(finalImages[j],
                           (int(float(1.0 - angle / 180.0) * testWidth),
                            int(testHeight / 2)), 10, (0, 0, 225), -1)
                SiamfcVid.write(finalImages[j])
                cv2.imwrite(frame_name_list[j][0:-4] + '_siamfc.png',
                            finalImages[j])
                fname = fname + 1
            #break
    f.close()
    SiamfcVid.release()
    return
def main():
    #avoid printing TF debugging information
    #仅显示error log
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    #TODO:allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()

    #gt_,frame_name_list_,_,_=_init_video(env,evaluation,evaluation.video)
    #pos_x,pos_y,target_w,target_h=region_to_bbox(gt_[0])
    #print('---target_w---'+"%d"%target_w+'--target_h---'+"%d"%target_h)
    #why?????????????
    #Set size for use with tf.image.resize_images with align_corners=True
    #For example:
    # [1,4,7]=>[1 2 3 4 5 6 7]  (length 3*(3-1)+1)
    #instead of
    #[1,4,7]=>[1 1 2 3 4 5 6 7 7](length 3*3)
    #Why hp.response_up???
    #design.score_sz=33
    #hp.response_up=8
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    #build TF graph once for all
    #filename,image,templates_z,scores are only processes.!!!
    #真正返回信息需要用sess去执行(tracker中执行)
    #return filename, image, templates_z, scores_up
    filename, image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env)

    #iterate through all videos of evaluation dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        #os.listdir(path):返回指定路径下的文件和文件夹
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        #遍历不同的视频样本
        for i in range(nv):
            #frame_name_list:each image of a video sequence
            gt, frame_name_list, frame_sz, n_frames = _init_video(
                env, evaluation, videos_list[i])
            #np.rint():对浮点数取整但不改变浮点数类型
            #n_subseq=3
            starts = np.rint(
                np.linspace(0, n_frame - 1, evaluation.n_subseq + 1))
            #分成n_subseq+1份,将数组赋给starts
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                start_frame = int(starts[j])
                #start_frame:指start_frame及以后(选取了n_subseq中的一份)
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                #Update
                bboxes, speed[idx] = tracker(
                    hp,
                    run,
                    design,
                    env,
                    evaluation,
                    frame_name_list_,
                    pos_x,
                    pos_y,
                    #bboxes,speed[idx]=tracker(hp,run,design,frame_name_list_,pos_x,pos_y,
                    target_w,
                    target_h,
                    final_score_sz,
                    filename,
                    image,
                    templates_z,
                    scores,
                    start_frame)
                #gt_:ground truth
                #bboxes:the result of tracking
                lengths[idx], precisions[idx], precisions_auc[idx], ious[
                    idx] = _compile_results(gt_, bboxes,
                                            evaluation.dist_threshold)
                print(
                    str(i) + '--' + videos_list[i] + '--Precision: ' +
                    "%.2f" % precisions[idx] + '--Precisions AUC: ' +
                    "%.2f" % precisions_auc[idx] + '--IOU: ' +
                    "%.2f" % ious[idx] + '--Speed: ' + "%.2f" % speed[idx] +
                    '--')

    else:
        #evaluation.video='all'
        print(evaluation.video)
        gt, frame_name_list, _, _ = _init_video(env, evaluation,
                                                evaluation.video)
        #evaluation.start_frame=0
        pos_x, pos_y, target_w, target_h = region_to_bbox(
            gt[evaluation.start_frame])

        #Update
        #bboxes,speed=tracker(hp,run,design,frame_name_list,pos_x,pos_y,target_w,target_h,final_score_sz,
        bboxes, speed = tracker(hp, run, design, env, evaluation,
                                frame_name_list, pos_x, pos_y, target_w,
                                target_h, final_score_sz, filename, image,
                                templates_z, scores, evaluation.start_frame)
        _, precision, precisions_auc, iou = _compile_results(
            gt, bboxes, evaluation.dist_threshold)
        #print(evaluation.video+
        print(evaluation.video + '--Precision: ' +
              "(%d px)" % evaluation.dist_threshold + ': ' +
              "%.2f" % precision + '--Precisions AUC: ' +
              "%.2f" % precisions_auc + '--IOU: ' + "%.2f" % iou +
              '--Speed: ' + "%.2f" % speed + '--')
Пример #14
0
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    filename, image, templates_z, scores = siam.build_tracking_graph(
        final_score_sz, design, env)

    # iterate through all videos of evaluation.dataset
    if evaluation.video == 'all':
        dataset_folder = os.path.join(env.root_dataset, evaluation.dataset)
        videos_list = [v for v in os.listdir(dataset_folder)]
        videos_list.sort()
        nv = np.size(videos_list)
        speed = np.zeros(nv * evaluation.n_subseq)
        precisions = np.zeros(nv * evaluation.n_subseq)
        precisions_auc = np.zeros(nv * evaluation.n_subseq)
        ious = np.zeros(nv * evaluation.n_subseq)
        lengths = np.zeros(nv * evaluation.n_subseq)
        for i in range(nv):
            gt, frame_name_list, frame_sz, n_frames = _init_video(
                env, evaluation, videos_list[i])
            starts = np.rint(
                np.linspace(0, n_frames - 1, evaluation.n_subseq + 1))
            starts = starts[0:evaluation.n_subseq]
            for j in range(evaluation.n_subseq):
                start_frame = int(starts[j])
                gt_ = gt[start_frame:, :]
                frame_name_list_ = frame_name_list[start_frame:]
                pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
                idx = i * evaluation.n_subseq + j
                # Call Tracker for the selected sequence
                print("Tracking started!")
                bboxes, speed[idx] = tracker(hp, run, design, frame_name_list_,
                                             pos_x, pos_y, target_w, target_h,
                                             final_score_sz, filename, image,
                                             templates_z, scores, start_frame)
                lengths[idx], precisions[idx], precisions_auc[idx], ious[
                    idx] = _compile_results(gt_, bboxes,
                                            evaluation.dist_threshold)
                print( str(i) + ' -- ' + videos_list[i] + \
                ' -- Precision: ' + "%.2f" % precisions[idx] + \
                ' -- Precisions AUC: ' + "%.2f" % precisions_auc[idx] + \
                ' -- IOU: ' + "%.2f" % ious[idx] + \
                ' -- Speed: ' + "%.2f" % speed[idx] + ' --' )

        tot_frames = np.sum(lengths)
        mean_precision = np.sum(precisions * lengths) / tot_frames
        mean_precision_auc = np.sum(precisions_auc * lengths) / tot_frames
        mean_iou = np.sum(ious * lengths) / tot_frames
        mean_speed = np.sum(speed * lengths) / tot_frames
        print('-- Overall stats (averaged per frame) on ' + str(nv) +
              ' videos (' + str(tot_frames) + ' frames) --')
        print( ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % mean_precision +\
              ' -- Precisions AUC: ' + "%.2f" % mean_precision_auc +\
              ' -- IOU: ' + "%.2f" % mean_iou +\
              ' -- Speed: ' + "%.2f" % mean_speed + ' --' )

    else:
        gt, frame_name_list, _, n_frames = _init_video(env, evaluation,
                                                       evaluation.video)
        #pos_x, pos_y, target_w, target_h = region_to_bbox(gt[evaluation.start_frame])

        # np.size(frame_name_list) = Amount of frames
        # ott = amount of Objects To Track
        ott = len(gt) if evaluation.multi_object else 1
        objects = np.zeros((ott, 4))
        for i in range(ott):
            objects[i, :] = region_to_bbox(gt[i])

        # Call Tracker for the selected sequence.
        print("Tracking started!")
        bboxes, speed = tracker(hp, run, design, frame_name_list, objects,
                                final_score_sz, filename, image, templates_z,
                                scores, evaluation.start_frame)

        if evaluation.multi_object:
            print('No Ground Truth available for multi object, just printing speed result....\n' + \
                  evaluation.video + \
                  ' -- Speed: ' + "%.2f" % speed + ' --' )
        else:
            _, precision, precision_auc, iou = _compile_results(
                gt, bboxes, evaluation.dist_threshold)
            print( evaluation.video + \
                  ' -- Precision ' + "(%d px)" % evaluation.dist_threshold + ': ' + "%.2f" % precision +\
                  ' -- Precision AUC: ' + "%.2f" % precision_auc + \
                  ' -- IOU: ' + "%.2f" % iou + \
                  ' -- Speed: ' + "%.2f" % speed + ' --' )
    print("Tracking finished!")
Пример #15
0
def main():
    # avoid printing TF debugging information
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
    # TODO: allow parameters from command line or leave everything in json files?
    hp, evaluation, run, env, design = parse_arguments()
    # Set size for use with tf.image.resize_images with align_corners=True.
    # For example,
    #   [1 4 7] =>   [1 2 3 4 5 6 7]    (length 3*(3-1)+1)
    # instead of
    # [1 4 7] => [1 1 2 3 4 5 6 7 7]  (length 3*3)
    final_score_sz = hp.response_up * (design.score_sz - 1) + 1
    # build TF graph once for all
    filename, image, templates_z, templates_x, scores, scores_original = siam.build_tracking_graph(
        final_score_sz, design, env)

    # create dataset
    dataset = DatasetFactory.create_dataset(name=args_dataset,
                                            dataset_root=dataset_root,
                                            load_img=False)

    # iterate through all videos of evaluation.dataset
    videos_list = list(dataset.videos.keys())
    videos_list.sort()
    nv = np.size(videos_list)
    for i in range(nv):
        current_key = sorted(list(dataset.videos.keys()))[i]
        gt, frame_name_list, frame_sz, n_frames = _init_video(
            dataset, current_key)
        for j in range(1):
            start_frame = 0
            gt_ = gt[start_frame:, :]
            frame_name_list_ = frame_name_list[start_frame:]
            pos_x, pos_y, target_w, target_h = region_to_bbox(gt_[0])
            bboxes, _ = tracker(videos_list[i], hp, run, design,
                                frame_name_list_, pos_x, pos_y, target_w,
                                target_h, final_score_sz, filename, image,
                                templates_z, templates_x, scores,
                                scores_original, start_frame)

            #Visualize
            if visualize:
                for bbox, groundt, frame_name in zip(bboxes, gt_,
                                                     frame_name_list_):
                    image = cv2.imread(frame_name)
                    bbox_pt1, bbox_pt2 = get_bbox_cv(bbox)
                    bbox_gt1, bbox_gt2 = get_gt_bbox_cv(groundt)

                    #Draw result
                    cv2.rectangle(image, bbox_pt1, bbox_pt2, (0, 255, 0))
                    #Draw ground truth
                    cv2.rectangle(image, bbox_gt1, bbox_gt2, (0, 0, 0))
                    cv2.imshow("Results:", image)
                    cv2.waitKey()

            bboxes = bboxes.tolist()
            bboxes[0] = [1]
            target_dir = os.path.join(result_output, current_key)
            if not os.path.exists(target_dir):
                os.mkdir(target_dir)
            results_file = current_key + "_" + "{:03d}".format(1) + ".txt"
            results_abs_file = os.path.join(target_dir, results_file)
            with open(results_abs_file, "w") as f:
                for bbox in bboxes:
                    if len(bbox) == 1:
                        f.write('%d\n' % (bbox[0]))
                    else:
                        f.write('%.2f, %.2f, %.2f, %.2f\n' %
                                (bbox[0], bbox[1], bbox[2], bbox[3]))