def run_SiamFC(seq, rp, saveimage): x = seq.init_rect[0] y = seq.init_rect[1] w = seq.init_rect[2] h = seq.init_rect[3] tic = time.clock() # starting tracking tracker = SiamFCTracker(config.model_path, config.gpu_id) res = [] for idx, frame in enumerate(seq.s_frames): frame = cv2.cvtColor(cv2.imread(frame), cv2.COLOR_BGR2RGB) if idx == 0: bbox = (x, y, w, h) tracker.init(frame, bbox) bbox = (bbox[0], bbox[1], bbox[0] + bbox[2], bbox[1] + bbox[3] ) # 1-idx else: bbox = tracker.update(frame) res.append( (bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1])) # 1-idx duration = time.clock() - tic result = {} result['res'] = res result['type'] = 'rect' result['fps'] = round(seq.len / duration, 3) return result
def main(video_dir, gpu_id, model_path): # load videos filenames = sorted(glob.glob(os.path.join(video_dir, "img/*.jpg")), key=lambda x: int(os.path.basename(x).split('.')[0])) frames = [ cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB) for filename in filenames ] gt_bboxes = pd.read_csv(os.path.join(video_dir, "groundtruth_rect.txt"), sep='\t|,| ', header=None, names=['xmin', 'ymin', 'width', 'height'], engine='python') title = video_dir.split('/')[-1] # starting tracking tracker = SiamFCTracker(model_path, gpu_id) for idx, frame in enumerate(frames): if idx == 0: bbox = gt_bboxes.iloc[0].values tracker.init(frame, bbox) bbox = (bbox[0] - 1, bbox[1] - 1, bbox[0] + bbox[2] - 1, bbox[1] + bbox[3] - 1) else: bbox = tracker.update(frame) # bbox xmin ymin xmax ymax frame = cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (0, 255, 0), 2) gt_bbox = gt_bboxes.iloc[idx].values gt_bbox = (gt_bbox[0], gt_bbox[1], gt_bbox[0] + gt_bbox[2], gt_bbox[1] + gt_bbox[3]) frame = cv2.rectangle( frame, (int(gt_bbox[0] - 1), int(gt_bbox[1] - 1)), # 0-index (int(gt_bbox[2] - 1), int(gt_bbox[3] - 1)), (255, 0, 0), 1) if len(frame.shape) == 3: frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) frame = cv2.putText(frame, str(idx), (5, 20), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 255, 0), 1) cv2.imshow(title, frame) cv2.waitKey(30)
def main(video_dir, gpu_id, model_path): # load videos filenames = sorted(glob.glob(os.path.join(video_dir, "img/*.jpg")), key=lambda x: int(os.path.basename(x).split('.')[0])) frames = [cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB) for filename in filenames] first_frame = frames[0] #extract person detections and sort it from largest to smallest person_detections = list(set(filter(lambda x:x[1]=='person', yolo(first_frame)))) person_detections.sort(key=lambda x: (x[0][2] * x[0][3]), reverse=True) title = video_dir.split('/')[-1] # starting tracking trackers = [] bboxes = [] bboxes_colours = [] for i in range(len(person_detections)): trackers.append(SiamFCTracker(model_path, gpu_id)) bboxes.append(person_detections[i][0]) bboxes_colours.append((randint(0, 255) % 255, randint(0, 255), randint(0, 255))) for idx, frame in enumerate(frames): if idx == 0: for t in range(len(trackers)): trackers[t].init(frame, person_detections[t][0]) bboxes[t] = (bboxes[t][0]-1, bboxes[t][1]-1, bboxes[t][0]+ bboxes[t][2]-1, bboxes[t][1]+ bboxes[t][3]-1) else: for t in range(len(trackers)): bboxes[t] = trackers[t].update(frame) # bbox xmin ymin xmax ymax for t in range(len(trackers)): frame = cv2.rectangle(frame, (int(bboxes[t][0]), int(bboxes[t][1])), (int(bboxes[t][2]), int(bboxes[t][3])), bboxes_colours[t], 2) if len(frame.shape) == 3: frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) frame = cv2.putText(frame, str(idx), (5, 20), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 255, 0), 1) cv2.imshow(title, frame) cv2.waitKey(30)
from __future__ import absolute_import #?? import os from got10k.datasets import * from siamfc import SiamFCTracker # import multiprocessing # multiprocessing.set_start_method('spawn',True) if __name__ == '__main__': root_dir = os.path.abspath('data/GOT-10k') #获取当前工作目录 seqs = GOT10k(root_dir, subset='train', return_meta=True) tracker = SiamFCTracker(net_path='./models/CIResNet22_PRETRAIN.model', train=True) #优化器,GPU,损失函数,网络模型 tracker.train_over(seqs)
if __name__ == '__main__': parser = argparse.ArgumentParser(description='siamfcres22 tracking') #.add_argument('--dataset',default='VOT2018', type=str,help='datasets') #parser.add_argument('--save_path', default='./results', type=str,help='config file') #parser.add_argument('--snapshot', default=snapshot, type=str,help='snapshot of models to eval') parser.add_argument('--model_path', default='./models/siamfcres22_50.pth', type=str, help='eval one special video') # parser.add_argument('--video', default='', type=str, help='eval one special video') #parser.add_argument('--vis', action='store_true',help='whether visualzie result') args = parser.parse_args() tracker = SiamFCTracker(net_path=args.model_path, train=False) #初始化一个追踪器 # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2013) root_dir = os.path.abspath('datasets/OTB') e = ExperimentOTB(root_dir, version=2015) # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV123') # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV20L') # root_dir = os.path.abspath('datasets/DTB70') # e = ExperimentDTB70(root_dir)
from __future__ import absolute_import #?? import os import sys sys.path.append(os.getcwd()) from got10k.datasets import * from siamfc import SiamFCTracker os.environ["CUDA_VISIBLE_DEVICES"] = "0,1" #多卡情况下默认多卡训练,如果想单卡训练,设置为"0" if __name__ == '__main__': root_dir = os.path.abspath('data/GOT-10k') #获取当前工作目录 seqs = GOT10k(root_dir, subset='train', return_meta=True) # group=2 是分组卷积, group=1 是原始的alexnet tracker = SiamFCTracker(model_path='./models/alexnet.pth') tracker.train_over(seqs)
#parser.add_argument('--snapshot', default=snapshot, type=str,help='snapshot of models to eval') parser.add_argument('--model_path', default='./models/siamfc_41.pth', type=str, help='eval one special video') # parser.add_argument('--video', default='', type=str, help='eval one special video') #parser.add_argument('--vis', action='store_true',help='whether visualzie result') args = parser.parse_args() # OTB100 单机,单GPU,8b,siamfc_50.pth -prec_score:0.790 -succ_score:0.591 -succ_rate:0.735 # OTB100 单机,2-GPU,8b,siamfc_50.pth -prec_score:0.756 -succ_score:0.563 -succ_rate:0.699 # OTB100 单机,2-GPU,16b,siamfc_50.pth -prec_score:0.760 -succ_score:0.575 -succ_rate:0.721 # OTB100 单机,2-GPU,16b,siamfc_38.pth -prec_score:0.755 -succ_score:0.569 -succ_rate:0.711 tracker = SiamFCTracker(model_path=args.model_path) #初始化一个追踪器 # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2013) root_dir = os.path.abspath('datasets/OTB') e = ExperimentOTB(root_dir, version=2015) # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV123') # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV20L') # root_dir = os.path.abspath('datasets/DTB70') # e = ExperimentDTB70(root_dir)
import multiprocessing multiprocessing.set_start_method('spawn', True) gpu_id = 0 model_path = './models/siamfc_30.pth' # model_gpu=nn.DataParallel(model,device_ids=[0,1])# 多GPU并行计算 # output=model_gpu(input) if __name__ == '__main__': tracker = SiamFCTracker(model_path, gpu_id) #初始化一个追踪器 # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2013) # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2015) root_dir = os.path.abspath('datasets/UAV123') e = ExperimentUAV123(root_dir, version='UAV123') # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV20L') # root_dir = os.path.abspath('datasets/DTB70') # e = ExperimentDTB70(root_dir)
from __future__ import absolute_import import os import glob import numpy as np from siamfc import SiamFCTracker if __name__ == '__main__': seq_dir = os.path.expanduser('~/data/OTB/Crossing') img_files = sorted(glob.glob(seq_dir + 'img/*.jpg')) anno = np.loadtxt(seq_dir + 'groundtruth_rect.txt') net_path = './models/siamfcres22_50.pth' tracker = SiamFCTracker(net_path=net_path) tracker.track(img_files, anno[0], visualize=True)
def main(): # parse arguments parser = argparse.ArgumentParser(description="Demo SiamFC") parser.add_argument('-v', '--video', default='./video/Basketball', type=str, help="the path of video directory") parser.add_argument('-g', '--gpuid', default=0, type=int, help="the id of GPU") parser.add_argument('-m', '--model', default='./models/siamfc_pretrained.pth', type=str, help="the path of model") args = parser.parse_args() video_dir = args.video gpu_id = args.gpuid model_path = args.model # load videos filenames = sorted(glob.glob(os.path.join(video_dir, "img/*.jpg")), key=lambda x: int(os.path.basename(x).split('.')[0])) frames = [ cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB) for filename in filenames ] gt_bboxes = pd.read_csv(os.path.join(video_dir, "groundtruth_rect.txt"), sep='\t|,| ', header=None, names=['xmin', 'ymin', 'width', 'height'], engine='python') title = video_dir.split('/')[-1] # starting tracking tracker = SiamFCTracker(model_path, gpu_id) for idx, frame in enumerate(frames): if idx == 0: bbox = gt_bboxes.iloc[0].values tracker.init(frame, bbox) bbox = (bbox[0] - 1, bbox[1] - 1, bbox[0] + bbox[2] - 1, bbox[1] + bbox[3] - 1) else: bbox = tracker.update(frame) # bbox xmin ymin xmax ymax frame = cv2.rectangle(frame, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (0, 255, 0), 2) gt_bbox = gt_bboxes.iloc[idx].values gt_bbox = (gt_bbox[0], gt_bbox[1], gt_bbox[0] + gt_bbox[2], gt_bbox[1] + gt_bbox[3]) frame = cv2.rectangle( frame, (int(gt_bbox[0] - 1), int(gt_bbox[1] - 1)), # 0-index (int(gt_bbox[2] - 1), int(gt_bbox[3] - 1)), (255, 0, 0), 1) if len(frame.shape) == 3: frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) frame = cv2.putText(frame, str(idx), (5, 20), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 255, 0), 1) cv2.imshow(title, frame) cv2.waitKey(30)
for i in args.instance_size: cfg['instance_size'] = i for l in args.scale_lr: cfg['scale_lr'] = l for k in args.scale_penalty: cfg['scale_penalty'] = k for w in args.window_influence: cfg['window_influence'] = w count += 1 tracker = SiamFCTracker(args.model_path, True, 0, cfg) # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2013) root_dir = os.path.abspath('datasets/OTB') e = ExperimentOTB(root_dir, version=2015) # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV123') # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV20L') # root_dir = os.path.abspath('datasets/DTB70') # e = ExperimentDTB70(root_dir)
for i in args.instance_size: cfg['instance_size'] = i for l in args.scale_lr: cfg['scale_lr'] = l for k in args.scale_penalty: cfg['scale_penalty'] = k for w in args.window_influence: cfg['window_influence'] = w count += 1 tracker = SiamFCTracker(args.model_path, cfg) # root_dir = os.path.abspath('datasets/OTB') # e = ExperimentOTB(root_dir, version=2013) root_dir = os.path.abspath('datasets/OTB') e = ExperimentOTB(root_dir, version=2015) # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV123') # root_dir = os.path.abspath('datasets/UAV123') # e = ExperimentUAV123(root_dir, version='UAV20L') # root_dir = os.path.abspath('datasets/DTB70') # e = ExperimentDTB70(root_dir)