1、序列化测试
对于一些跟踪算法,特别是siamese系列,一般进行20epochs的训练,对应20个训练模型,特别是backbone解冻的后10个模型,均有可能出现最好的结果(got-10k与lasot的结果一般容易出现在10-15,;otb通用模型的最好结果一般出现在15-20轮)。所以就需要对所有的model进行测试,而手动测试需要自己盯着每次测试结束后再次运行,比较麻烦,所以再此贴出一个序列化测试的代码(自行调整从strat_epoch-end_epoch的模型测试)。
import sys
sys.path.append("..")
import os
import time
import argparse
from mpi4py import MPI
# 多个GPU同时进行测试多个epoch
parser = argparse.ArgumentParser(description="multi-gpu test all epochs")
parser.add_argument("--start_epoch", default=13, type=int, help="test end epoch")
parser.add_argument("--end_epoch", default=20, type=int, help="test end epoch")
parser.add_argument("--gpu_nums", default=2, type=int, help="gpu numbers")
# parser.add_argument("--threads", default=2, type=int, required=True)
parser.add_argument("--dataset", default="VOT2018", type=str, help="benchmark to test")
args = parser.parse_args()
# init gpu and epochs
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
GPU_ID = rank % args.gpu_nums
node_name = MPI.Get_processor_name() # get the name of the node
os.environ["CUDA_VISIBLE_DEVICES"] = str(GPU_ID)
print("node name: {}, GPU_ID: {}".format(node_name, GPU_ID))
time.sleep(rank * 5)
start_epoch = args.start_epoch
# run test scripts -- one epoch for each thread
for i in range(args.end_epoch - args.start_epoch + 1):
dataset = args.dataset
# try:
# epoch_ID += args.threads
# except:
# epoch_ID = rank % (args.end_epoch - args.start_epoch + 1) + args.start_epoch
epoch_ID = start_epoch + i
if epoch_ID > args.end_epoch:
continue
snapshot = "snapshot/checkpoint_e{}.pth".format(epoch_ID)
print("==> test {}th epoch".format(epoch_ID))
os.system("python test.py --dataset {0} --snapshot {1} --config ../experiments/siamgat_googlenet_vot/config.yaml".format(dataset, snapshot))
2、模型搜参
对于跟踪来说,特别是siamese模型来说,训练出一个模型之后很重要的一点就是模型搜参(window_inf/penalty_k/lr),一个合适的参数对于模型的性能提升很大,这也是为什么复现一些算法模型时,往往不能达到论文中的精度。
这里还是要用到@回忆浅离博主git上的代码,链接:https://github.com/Giveupfree/SiamCAR-CAM/tree/master/tools,执行tune.py即可进行对应的搜参,可以同时对不同的数据集进行搜参,以提高效率。搜参的过程相当于自动使用不同的参数值去测试,“试”出最好的结果,目前设置为500轮,所以需要的时间会比较久,OTB100/GOT-10k大约一周,VOT大约4天,LaSOT大约20多天。
其中关于GOT-10k的搜参,需要将SOTDrawRect项目SOT_eval文件夹中的GOT-10k-test.json更名为GOT-10k.json,并替换GOT-10k数据集中的json(因为默认的json文件没有GT框标注),最后说明GOT-10k搜到的结果与实际有出入,因为是相当于与自制的json做IOU,所以不一定搜到的结果高,实际就高,还需要一一上传官网进行测试。
最后说明,搜出的参数小数很长,如果想要使用搜好的参数进行测试,必须要使用带有全部小数的参数进行测试,才能得到最好的效果。其中的module_builder,以及其中的测试算法需要根据自身实际使用的算法进行对应的小改动。