训练除 yolox_s 以外的 YOLOX 模型及训练参数修改
YOLOX 的模子及训练设置装备摆设模板文件位于./yolox/exp/yolox_base.py,关于VOC格局的数据能够模仿./exps/example/yolox_voc/yolox_voc_s.py停止修改1. 改换 yolox_m、yolox_l、yolox_x 及其他模子YOLOX的github响应的预训练权重如下:ModelsizemAPval 0.5:0.95mAPtest 0.5:0.95Speed V100 (ms)Params (M)FLOPs (G)YOLOX-s64040.540.59.89.026.8YOLOX-m64046.947.212.325.373.8YOLOX-l64049.750.114.554.2155.6YOLOX-x64051.151.517.399.1281.9YOLOX-Darknet5364047.748.011.163.7185.3from yolox.exp import Exp as MyExp # 若是其余参数不需要修改的话能够只改以下两行参数 # yolox_m class Exp(MyExp): def __init__(self): super(Exp, self).__init__() self.num_classes = 7 self.depth = 0.67 # 修改那个参数 self.width = 0.75 # 修改那个参数 # yolox_m class Exp(MyExp): def __init__(self): super(Exp, self).__init__() self.num_classes = 7 self.depth = 1 # 修改那个参数 self.width = 1 # 修改那个参数 # yolox_x class Exp(MyExp): def __init__(self): super(Exp, self).__init__() self.num_classes = 7 self.depth = 1.33 # 修改那个参数 self.width = 1.25 # 修改那个参数 yolox-Darknet53 还需要重写 get_model 函数 详见github import os import torch.nn as nn from yolox.exp import Exp as MyExp class Exp(MyExp): def __init__(self): super(Exp, self).__init__() self.depth = 1.0 self.width = 1.0 self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] def get_model(self, sublinear=False): def init_yolo(M): for m in M.modules(): if isinstance(m, nn.BatchNorm2d): m.eps = 1e-3 m.momentum = 0.03 if "model" not in self.__dict__: from yolox.models import YOLOX, YOLOFPN, YOLOXHead backbone = YOLOFPN() head = YOLOXHead(self.num_classes, self.width, in_channels=[128, 256, 512], act="lrelu") self.model = YOLOX(backbone, head) self.model.apply(init_yolo) self.model.head.initialize_biases(1e-2) return self.model 2. 更改其他训练参数不建议间接修改./yolox/exp/yolox_base.py,建议模仿./exps/example/yolox_voc/yolox_voc_s.py停止响应修改from yolox.exp import Exp as MyExp class Exp(MyExp): def __init__(self): super(Exp, self).__init__() # ---------------- model config ---------------- # self.num_classes = 7 # 数据中的类别 self.depth = 1.33 # 模子的深度 self.width = 1.25 # 模子的宽度 self.act = "silu" # 模子的激活函数(relu、silu等) # ---------------- dataloader config ---------------- # self.data_num_workers = 4 # 若是训练过程占用内存太多,能够削减该值 self.input_size = (640, 640) # (高、宽) self.multiscale_range = 5 # 现实多标准训练中图片范畴为[640 - 5 * 32, 640 + 5 * 32],若是需要打消则设定为0 # self.random_size = (14, 26) # 打消正文那行来详细设定标准范畴 self.data_dir = None # 数据集图片的位置,若是为None则利用“dataset”文件的途径 self.train_ann = "instances_train2017.json" # name of annotation file for training self.val_ann = "instances_val2017.json" # name of annotation file for evaluation self.test_ann = "instances_test2017.json" # name of annotation file for testing # --------------- transform config ----------------- # self.mosaic_prob = 1.0 # 应用 mosaic aug 的概率 self.mixup_prob = 1.0 # 应用 mixup aug 的概率 self.hsv_prob = 1.0 # 应用 hsv aug 的概率 self.flip_prob = 0.5 # 应用 flip aug 的概率 self.degrees = 10.0 # 扭转角度区间 那里是 (-10,10) self.translate = 0.1 # 转换区间 那里是 (-0.1, 0.1) self.mosaic_scale = (0.1, 2) # 马赛克标准 self.enable_mixup = True # 能否应用 mixup aug self.mixup_scale = (0.5, 1.5) # mixup aug 标准 self.shear = 2.0 # shear angle 区间,那里是 (-2, 2) # -------------- training config --------------------- # self.warmup_epochs = 5 # warmup epoch 数 self.max_epoch = 300 # 更大训练 epoch self.warmup_lr = 0 # warmup 期间最小的 learning rate self.min_lr_ratio = 0.05 # 最小的 learning rate self.basic_lr_per_img = 0.01 / 64.0 # learning rate for one image. During training, lr will multiply batchsize. self.scheduler = "yoloxwarmcos" # LRScheduler 名字 self.no_aug_epochs = 15 # 最初 n 轮不利用 augmention like mosaic self.ema = True # 在训练中接纳 EMA self.weight_decay = 5e-4 # 优化器的 weight_decay self.momentum = 0.9 # 优化器的 momentum self.print_interval = 10 # 迭代中输出日记的频次,若是设定为1则每次都输出log self.eval_interval = 10 # 训练过程中评估的 epoch 频次,那里每10个 epoch 会评估一次 self.save_history_ckpt = True # 能否保留训练汗青的 checkpoint,若是是 False 则只要 latest and best ckpt self.exp_name = os.path.split(os.path.realpath(__file__))[1].split(".")[0] # 尝试名字 # ----------------- testing config ------------------ # self.test_size = (640, 640) # evaluation/test 期间的图片大小 self.test_conf = 0.01 # evaluation/test 的输出阈值,可能性大于该阈值的预测成果才会被输出 self.nmsthre = 0.65 # nms 阈值