/easy-track

Primary LanguagePythonMIT LicenseMIT

easy-track toolkit

state

  • Now: under development

Install

git clone https://github.com/LiYunfengLYF/easy-track
cd easy-track
python setup.py build
python setup.py install

Document

Python API (Directory)

test functions   | quick_start | run_sequence |
                        | report_seq_performance |

board functions |

read functions  | imread | txtread | seqread |
                         | img_filter | selectROI | img2tensor |

show functions | imshow | seqshow | close_cv2_window | speed2waitkey |
                         | show_otb | show_lasot | show_uot | show_utb |

draw functions  | draw_box |

script functions | remove_timetxt | remove_same_img |
                         | trans_txt_delimiter | trans_imgs_order_name |
                         | extract_weights_from_checkpoint | show_checkpoint_keys |

trackers | SiamFC | Stark | OSTrack | LightFC |

test functions

quick_start

def quick_start(tracker, seq_file, speed=20, imgs_type='.jpg'):
    """
    Description
        quick_start aim to help user to quickly observe the results of the tracker on an image sequence.
        It manually selects the initial bounding box and show results in each image by using blue bounding box.
    
    Params:
        tracker:
        seq_file:
        speed:      FPS speed, default = 20
        imgs_type:  image type, default = '.jpg'
    
    """

run_sequence

def run_sequence(tracker, seq_file, gt_file=None, save_path=None, save=False, visual=False, speed=20, imgs_type='.jpg',
                 select_roi=False, report_performance=True):
    """
    Description


    Params:
        tracker:    
        seq_file:   
        speed:      FPS speed, default = 20
        imgs_type:  image type, default = '.jpg'
    """

report_seq_performance

def report_seq_performance(gt_file, results_file):
    """
    Description
        calc Success Score, Precision Score, Norm Precision Score, Success Rate of on a sequence

    Params:
        gt_file:        str
        results_file:   str   

    """

read functions

imread

def imread():
    """
    Description
        imread is an extension of cv2.imread, which returns RGB images

    Params:
        filename:   the path of image
        
    Return:
        image:      np.array
    
    """

txtread

def txtread():
    """
    Description
        txtread is an extension of np.loadtxt, support ',' and '\t' delimiter.
        The original implementation method is in the pytracking library at https://github.com/visionml/pytracking

    Params:
        filename:           the path of txt
        delimiter:          default is [',','\t']
        dtype:              default is np.float64
    
    Return:
        ground_truth_rect:  np.array(n,4), n is length of results

    """

seqread

def seqread():
    """
    Description
        Seqread reads all image items in the file and sorts them by numerical name
        It returns a list containing the absolute addresses of the images

        Sorting only supports two types, '*/1.jpg' and '*/*_1.jpg'

    Params:
        file:       images' file
        imgs_type:  default is '.jpg'

    Return:
        List of absolute paths of sorted images

    """

img_filter

def img_filter():
    """
    Description
        img_filter retains items in the specified format in the input list

    Params:
        imgs_list:          List of image path
        extension_filter:   default is '.jpg'

    Return:
        List of images path  with extension
        
    """

selectROI

def selectROI(winname, img):
    """
    Description
        selectROI is an extension of cv2.selectROI
        input image is RGB rather BGR

    Params:
        winname:    name
        img:        np.array

    return:
        bbox:       [x,y,w,h]

    """

img2tensor

def img2tensor(img, device='cuda:0'):
    """
    Description
        transfer an img to a tensor
        mean: [0.485, 0.456, 0.406]
        std:  [0.229, 0.224, 0.225]

    Params:
        img:       np.array
        device:    default is 'cuda:0'

    return:
        Tensor:    torch.tensor(1,3,H,W)

    """

show functions

imshow

def imshow():
    """
    Description
        imshow is an extension of cv2.imshow
        Different with cv2.imshow, it input is an RGB image, and window size is variable 

    Params:
        winname:    window name
        image:      np.array
        waitkey:    default is 0
    
    """

seqshow

def seqshow():
    """
    Description
        seqshow visualizes the bounding box results of the tracker in image sequence

        if results_file is none, tracker results (default is red bounding box) will not be displayed on sequence
        if gt_file is none or show_gt is False, groundtruth (green bounding box) will not be displayed on sequence

    Params:
        imgs_file:      str
        imgs_type:      default is '.jpg', you can change it
        result_file:    str
        gt_file:        str
        show_gt:        True or False
        speed:          FPS
        tracker_name:   str
        seq_name:       str
        result_color:   default is red (0,0,255), you can change it
        thickness:      int
    
    """

close_cv2_window

def close_cv2_window(winname):
    """
    Description
        close an opened window of cv2

    Params:
        winname: str
        
    """

speed2waitkey

def speed2waitkey(speed):
    """
    Description
        trans fps to waitkey of cv2

    Params:
        speed:      fps, int

    return:
        waitket:    int
        
    """

show_otb

def show_otb(dataset_files, result_file=None, speed=20, result_color=(0, 0, 255), show_gt=True, tracker_name=r''):
    """
    Description
        show_otb visualizes the bounding box results of the tracker in otb benchmark

        if results_file is none, tracker results (default is red bounding box) will not be displayed on OTB
        if show_gt is False, groundtruth (green bounding box) will not be displayed on OTB

    Params:
        dataset_files:  str
        result_file:    str
        speed:          FPS, default is 20
        result_color:   default is red (0,0,255), you can change it
        show_gt:        True or False
        tracker_name:   str
        
    """

show_lasot

def show_lasot(dataset_files, result_file=None, speed=20, result_color=(0, 0, 255), show_gt=True, tracker_name=r''):
    """
    Description
        show_lasot visualizes the bounding box results of the tracker in lasot benchmark

        if results_file is none, tracker results (default is red bounding box) will not be displayed on lasot
        if show_gt is False, groundtruth (green bounding box) will not be displayed on lasot

    Params:
        dataset_files:  str
        result_file:    str
        speed:          FPS, default is 20
        result_color:   default is red (0,0,255), you can change it
        show_gt:        True or False
        tracker_name:   str
        
    """

show_uot

def show_uot(dataset_files, result_file=None, speed=20, result_color=(0, 0, 255), show_gt=True, tracker_name=r''):
    """
    Description
        show_uot visualizes the bounding box results of the tracker in uot benchmark

        if results_file is none, tracker results (default is red bounding box) will not be displayed on uot
        if show_gt is False, groundtruth (green bounding box) will not be displayed on uot

    Params:
        dataset_files:  str
        result_file:    str
        speed:          FPS, default is 20
        result_color:   default is red (0,0,255), you can change it
        show_gt:        True or False
        tracker_name:   str
        
    """

show_utb

def show_utb(dataset_files, result_file=None, speed=20, result_color=(0, 0, 255), show_gt=True, tracker_name=r''):
    """
    Description
        show_utb visualizes the bounding box results of the tracker in uot benchmark

        if results_file is none, tracker results (default is red bounding box) will not be displayed on utb
        if show_gt is False, groundtruth (green bounding box) will not be displayed on utb

    Params:
        dataset_files:  str
        result_file:    str
        speed:          FPS, default is 20
        result_color:   default is red (0,0,255), you can change it
        show_gt:        True or False
        tracker_name:   str
        
    """

draw functions

draw_box

def draw_box(image, box, color, thickness):
    """
    Description
        draw a bounding box on image
    
    Params:
        image:      np.array
        box:        [x, y, w, h]
        color:      bounding box color
        thickness:  bounding box thickness
    
    Return:
        image:      np.array
    
    """

script functions

remove_timetxt

def remove_timetxt(results_file):
    """
    Description
        Remove *_time.txt files from results_file

    Params:
        results_file:   file path
    
    """

remove_same_img

def remove_same_img(file, save_file, checkpoint_path=None, device='cuda:0', resize=(320, 640), thred=0.4, show_same=False):
    """
    Description
        Remove same images in file and sort and save the rest images in save file
        It resizes input image to (320,640)(default) and uses MobileNetV2 to extract feature, then calc the similarity
        You need to sign the checkpoint_path of mobilenet_v2-b0353104.pth (from torchvision) and thred (default is 0.4)
        if not sign checkpoint path, it will search for weights in the etrack_checkpoints directory of the running .py file
        show_same=True will show the same image pair
    
    Params:
        results_file:       file path
        save_file:          file path
        checkpoint_path:    checkpoint path

    """

trans_txt_delimiter

def trans_txt_delimiter(txt_file, out_file=None, delimiter=',', new_delimiter=None, with_time=True):
    """
    Description
        trans the delimiter of txt and save txt in out_file
        if out_file is none, out_file = txt_file
        if new_delimiter is none, new_delimiter = delimiter
        if with time is True, copy *_time.txt to out_file
        
    Params:
        txt_file:   source txt file
        out_file:   save txt file
        format:     ',' or '\t'
        new_format: ',' or '\t'
        with_time:  True or False

    """

trans_imgs_order_name

def trans_imgs_order_name(file, save_file, sort=True, imgs_format='.jpg', preread=True, format_name=False, width=4,
                    start=1, end=None, ):
    """
    Description
        transfer image into an order name, and save in save_file
        if sort is False, it will directly read images. The original order of imgs may not be preserved
        if preread is False, it will directly copy and paste, image will not be opened
        if format_name is True, images' name is like 0001.jpg, 0002.jpg (width=4), ... else 1.jpg, 2.jpg, ...
    
    Params:
        file:           str
        save_file:      str
        sort:           True or False
        imgs_format:    str, default is '.jpg'
        preread:        True or False
        format_name:    True or False
        width:          int
        start:          int 
        end:            int 

    """

extract_weights_from_checkpoint

def extract_weights_from_checkpoint(checkpoint_file, out_file=None, name=None, key=None):
    """
    Description
        extract model's weight from checkpoint
        if out_file is None, save weights to current file
        if name is None, use current checkpoint name
        if key is None, use default names: 'net', 'network', 'model'

    Params:
        checkpoint_file:    checkpoint file
        out_file:           save weight file
        name:               save name, str type
        key:                key name, str type
    
    """

show_checkpoint_keys

def show_checkpoint_keys():
    """
    Description
        show checkpoint keys

    Params:
        checkpoint_file:    checkpoint file

    """

trackers

How to obtain checkpoints for tracker in etrack-toolkit?
     go to tracker's official link, download the checkpoints
     then use extract_weights_from_checkpoint to extract the weight and rename it at the same time
     then the new checkpoint can be load in tracker directly

  • SiamFC
Tracker:  SiamFC
  Paper:  Fully-Convolutional Siamese Networks for Object Tracking
   Code:  https://github.com/huanglianghua/siamfc-pytorch     
  • Stark
Tracker:  Starks50, StarkST50, StarkST101
  Paper:  Learning Spatio-Temporal Transformer for Visual Tracking    
   Code:  https://github.com/researchmm/Stark     
  • OSTrack
Tracker:  OSTrack256, OSTrack384
  Paper:  Joint Feature Learning and Relation Modeling for Tracking: A One-Stream Framework    
   Code:  https://github.com/botaoye/OSTrack     
  • LightFC
Tracker:  LightFC
  Paper:  Lightweight Full-Convolutional Siamese Tracker   
   Code:  https://github.com/LiYunfengLYF/LightFC