欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于yolov8訓(xùn)練的一些改動及注意事項

 更新時間:2023年02月04日 10:16:47   作者:lindsayshuo  
Yolo是一種目標檢測算法,目標檢測的任務(wù)是從圖片中找出物體并給出其類別和位置,這篇文章主要給大家介紹了關(guān)于yolov8訓(xùn)練的一些改動及注意事項,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下

1、YOLOv8創(chuàng)新改進點:

1.1.Backbone

使用的依舊是CSP的思想,不過YOLOv5中的C3模塊被替換成了C2f模塊,實現(xiàn)了進一步的輕量化,同時YOLOv8依舊使用了YOLOv5等架構(gòu)中使用的SPPF模塊;

1.2.PAN-FPN

毫無疑問YOLOv8依舊使用了PAN的思想,不過通過對比YOLOv5與YOLOv8的結(jié)構(gòu)圖可以看到,YOLOv8將YOLOv5中PAN-FPN上采樣階段中的卷積結(jié)構(gòu)刪除了,同時也將C3模塊替換為了C2f模塊

1.3.Decoupled-Head

是不是嗅到了不一樣的味道?是的,YOLOv8走向了Decoupled-Head;

1.4.Anchor-Free

YOLOv8拋棄了以往的Anchor-Base,使用了Anchor-Free的思想;

1.5.損失函數(shù)

YOLOv8使用VFL Loss作為分類損失,使用DFL Loss+CIOU Loss作為分類損失;

1.6.樣本匹配

YOLOv8拋棄了以往的IOU匹配或者單邊比例的分配方式,而是使用了Task-Aligned Assigner匹配方式。

2、關(guān)于基于預(yù)訓(xùn)練模型的訓(xùn)練

yolov8版本更新后,代碼結(jié)構(gòu)也隨著更新,跟v5的結(jié)構(gòu)大不一樣,大部分接口以及網(wǎng)絡(luò)結(jié)構(gòu)也隨之改動,為了加速算法落地,我們在訓(xùn)練時一般會遷移一部分預(yù)訓(xùn)練參數(shù)從而是的模型達到較好的效果,但是若你的模型跟預(yù)訓(xùn)練模型只有一小部分相似,但是又想繼承這一小部分的特征,直接加載所有參數(shù)訓(xùn)練肯定是不可取的,那就需要進行神經(jīng)網(wǎng)絡(luò)的層凍結(jié),通過凍結(jié)一些層來使得模型加速擬合,減少參數(shù)訓(xùn)練量。例如:當你的網(wǎng)絡(luò)很復(fù)雜,他的前端網(wǎng)絡(luò)是一個 vgg-16 的分類網(wǎng)絡(luò),后面要拼接一個自己寫的功能網(wǎng)絡(luò),這個時候,你把 vgg-16 的網(wǎng)絡(luò)架構(gòu)定義好了之后,上網(wǎng)下載vgg-16 的訓(xùn)練好的網(wǎng)絡(luò)參數(shù),然后加載到你寫的網(wǎng)絡(luò)中,然后把 vgg-16 相關(guān)的層凍結(jié)掉,只訓(xùn)練你自己寫的小網(wǎng)絡(luò)的參數(shù)。這樣的話,你就可以省掉很多的運算資源和時間,提高效率。

注意:凍結(jié)網(wǎng)絡(luò)層之后,最好對網(wǎng)絡(luò)重新 compile 一下,否則在一些場景下不會生效,compile 才會生效。

廢話不多說了,上干貨

def _setup_train(self, rank, world_size):
        """
        Builds dataloaders and optimizer on correct rank process.
        """
        # model
        self.run_callbacks("on_pretrain_routine_start")
        ckpt = self.setup_model()
        self.model = self.model.to(self.device)
        freeze=[5]
        freeze = [f'model.{x}.' for x in (freeze if len(freeze) > 1 else range(freeze[0]))]  # layers to freeze
        for k, v in self.model.named_parameters():
            v.requires_grad = True  # train all layers
            # v.register_hook(lambda x: torch.nan_to_num(x))  # NaN to 0 (commented for erratic training results)
            if any(x in k for x in freeze):
                LOGGER.info(f'freezing {k}')
                v.requires_grad = False
        self.set_model_attributes()
        if world_size > 1:
            self.model = DDP(self.model, device_ids=[rank])
        # Check imgsz
        gs = max(int(self.model.stride.max() if hasattr(self.model, 'stride') else 32), 32)  # grid size (max stride)
        self.args.imgsz = check_imgsz(self.args.imgsz, stride=gs, floor=gs)
        # Batch size
        if self.batch_size == -1:
            if RANK == -1:  # single-GPU only, estimate best batch size
                self.batch_size = check_train_batch_size(self.model, self.args.imgsz, self.amp)
            else:
                SyntaxError('batch=-1 to use AutoBatch is only available in Single-GPU training. '
                            'Please pass a valid batch size value for Multi-GPU DDP training, i.e. batch=16')

        # Optimizer
        self.accumulate = max(round(self.args.nbs / self.batch_size), 1)  # accumulate loss before optimizing
        self.args.weight_decay *= self.batch_size * self.accumulate / self.args.nbs  # scale weight_decay
        self.optimizer = self.build_optimizer(model=self.model,
                                              name=self.args.optimizer,
                                              lr=self.args.lr0,
                                              momentum=self.args.momentum,
                                              decay=self.args.weight_decay)
        # Scheduler
        if self.args.cos_lr:
            self.lf = one_cycle(1, self.args.lrf, self.epochs)  # cosine 1->hyp['lrf']
        else:
            self.lf = lambda x: (1 - x / self.epochs) * (1.0 - self.args.lrf) + self.args.lrf  # linear
        self.scheduler = lr_scheduler.LambdaLR(self.optimizer, lr_lambda=self.lf)
        self.scheduler.last_epoch = self.start_epoch - 1  # do not move
        self.stopper, self.stop = EarlyStopping(patience=self.args.patience), False

        # dataloaders
        batch_size = self.batch_size // world_size if world_size > 1 else self.batch_size
        self.train_loader = self.get_dataloader(self.trainset, batch_size=batch_size, rank=rank, mode="train")
        if rank in {0, -1}:
            self.test_loader = self.get_dataloader(self.testset, batch_size=batch_size * 2, rank=-1, mode="val")
            self.validator = self.get_validator()
            metric_keys = self.validator.metrics.keys + self.label_loss_items(prefix="val")
            self.metrics = dict(zip(metric_keys, [0] * len(metric_keys)))  # TODO: init metrics for plot_results()?
            self.ema = ModelEMA(self.model)
        self.resume_training(ckpt)
        self.run_callbacks("on_pretrain_routine_end")

3、注意事項

freeze=[5]的意思是凍結(jié)前5層骨干網(wǎng)絡(luò),一般來說最大凍結(jié)前十層網(wǎng)絡(luò)(backbone)就可以了,如果全部凍結(jié),那么訓(xùn)練出來的模型將會啥也不是,同時注意修改ultralytics-main/ultralytics/yolo/cfg/default.yaml,以下是我的:

# Ultralytics YOLO ??, GPL-3.0 license
# Default training settings and hyperparameters for medium-augmentation COCO training
	
task: detect  # inference task, i.e. detect, segment, classify
mode: train  # YOLO mode, i.e. train, val, predict, export

# Train settings -------------------------------------------------------------------------------------------------------
model:  yolov8s.pt # path to model file, i.e. yolov8n.pt, yolov8n.yaml
data:  data/rubbish_classify.yaml  # path to data file, i.e. i.e. coco128.yaml
epochs: 300  # number of epochs to train for
patience: 500  # epochs to wait for no observable improvement for early stopping of training
batch: 16  # number of images per batch (-1 for AutoBatch)
imgsz: 640  # size of input images as integer or w,h
save: True  # save train checkpoints and predict results
cache: False  # True/ram, disk or False. Use cache for data loading
device:  # device to run on, i.e. cuda device=0 or device=0,1,2,3 or device=cpu
workers: 8  # number of worker threads for data loading (per RANK if DDP)
project:  # project name
name:  # experiment name
exist_ok: False  # whether to overwrite existing experiment
pretrained: 1  # whether to use a pretrained model
optimizer: SGD  # optimizer to use, choices=['SGD', 'Adam', 'AdamW', 'RMSProp']
verbose: True  # whether to print verbose output
seed: 0  # random seed for reproducibility
deterministic: True  # whether to enable deterministic mode
single_cls: False  # train multi-class data as single-class
image_weights: False  # use weighted image selection for training
rect: False  # support rectangular training
cos_lr: False  # use cosine learning rate scheduler
close_mosaic: 10  # disable mosaic augmentation for final 10 epochs
resume: False  # resume training from last checkpoint
# Segmentation
overlap_mask: True  # masks should overlap during training (segment train only)
mask_ratio: 4  # mask downsample ratio (segment train only)
# Classification
dropout: 0.0  # use dropout regularization (classify train only)

# Val/Test settings ----------------------------------------------------------------------------------------------------
val: True  # validate/test during training
save_json: False  # save results to JSON file
save_hybrid: False  # save hybrid version of labels (labels + additional predictions)
conf:  # object confidence threshold for detection (default 0.25 predict, 0.001 val)
iou: 0.7  # intersection over union (IoU) threshold for NMS
max_det: 300  # maximum number of detections per image
half: False  # use half precision (FP16)
dnn: False  # use OpenCV DNN for ONNX inference
plots: True  # save plots during train/val

# Prediction settings --------------------------------------------------------------------------------------------------
source:  # source directory for images or videos
show: False  # show results if possible
save_txt: False  # save results as .txt file
save_conf: False  # save results with confidence scores
save_crop: False  # save cropped images with results
hide_labels: False  # hide labels
hide_conf: False  # hide confidence scores
vid_stride: 1  # video frame-rate stride
line_thickness: 3  # bounding box thickness (pixels)
visualize: False  # visualize model features
augment: False  # apply image augmentation to prediction sources
agnostic_nms: False  # class-agnostic NMS
classes:  # filter results by class, i.e. class=0, or class=[0,2,3]
retina_masks: False  # use high-resolution segmentation masks
boxes: True # Show boxes in segmentation predictions

# Export settings ------------------------------------------------------------------------------------------------------
format: torchscript  # format to export to
keras: False  # use Keras
optimize: False  # TorchScript: optimize for mobile
int8: False  # CoreML/TF INT8 quantization
dynamic: False  # ONNX/TF/TensorRT: dynamic axes
simplify: False  # ONNX: simplify model
opset:  # ONNX: opset version (optional)
workspace: 4  # TensorRT: workspace size (GB)
nms: False  # CoreML: add NMS

# Hyperparameters ------------------------------------------------------------------------------------------------------
lr0: 0.01  # initial learning rate (i.e. SGD=1E-2, Adam=1E-3)
lrf: 0.01  # final learning rate (lr0 * lrf)
momentum: 0.937  # SGD momentum/Adam beta1
weight_decay: 0.0005  # optimizer weight decay 5e-4
warmup_epochs: 3.0  # warmup epochs (fractions ok)
warmup_momentum: 0.8  # warmup initial momentum
warmup_bias_lr: 0.1  # warmup initial bias lr
box: 7.5  # box loss gain
cls: 0.5  # cls loss gain (scale with pixels)
dfl: 1.5  # dfl loss gain
fl_gamma: 0.0  # focal loss gamma (efficientDet default gamma=1.5)
label_smoothing: 0.0  # label smoothing (fraction)
nbs: 64  # nominal batch size
hsv_h: 0.015  # image HSV-Hue augmentation (fraction)
hsv_s: 0.7  # image HSV-Saturation augmentation (fraction)
hsv_v: 0.4  # image HSV-Value augmentation (fraction)
degrees: 0.0  # image rotation (+/- deg)
translate: 0.1  # image translation (+/- fraction)
scale: 0.5  # image scale (+/- gain)
shear: 0.0  # image shear (+/- deg)
perspective: 0.0  # image perspective (+/- fraction), range 0-0.001
flipud: 0.0  # image flip up-down (probability)
fliplr: 0.5  # image flip left-right (probability)
mosaic: 1.0  # image mosaic (probability)
mixup: 0.0  # image mixup (probability)
copy_paste: 0.0  # segment copy-paste (probability)

# Custom config.yaml ---------------------------------------------------------------------------------------------------
cfg:  # for overriding defaults.yaml

# Debug, do not modify -------------------------------------------------------------------------------------------------
v5loader: 1  # use legacy YOLOv5 dataloader

總結(jié)

到此這篇關(guān)于yolov8訓(xùn)練的一些改動及注意事項的文章就介紹到這了,更多相關(guān)yolov8訓(xùn)練改動內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解Python發(fā)送郵件實例

    詳解Python發(fā)送郵件實例

    這篇文章主要介紹了Python發(fā)送郵件實例,Python發(fā)送郵件需要smtplib和email兩個模塊,感興趣的小伙伴們可以參考一下
    2016-01-01
  • 在Python中操作列表之list.extend()方法的使用

    在Python中操作列表之list.extend()方法的使用

    這篇文章主要介紹了在Python中操作列表之list.extend()方法的使用,是Python入門學習中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-05-05
  • 使用Django實現(xiàn)文章與多個標簽關(guān)聯(lián)的示例詳解

    使用Django實現(xiàn)文章與多個標簽關(guān)聯(lián)的示例詳解

    在構(gòu)建一個博客或內(nèi)容管理系統(tǒng)時,經(jīng)常需要實現(xiàn)文章與標簽的關(guān)聯(lián),在 Django 中,我們可以利用 ManyToManyField 來實現(xiàn)文章與標簽的多對多關(guān)系,在本文中,我們將詳細探討如何使用 Django 模型實現(xiàn)文章與多個標簽的關(guān)聯(lián),需要的朋友可以參考下
    2023-11-11
  • matplotlib在python上繪制3D散點圖實例詳解

    matplotlib在python上繪制3D散點圖實例詳解

    這篇文章主要介紹了matplotlib在python上繪制3D散點圖實例詳解,首先介紹了官網(wǎng)的實例,然后分享了本文簡單代碼示例,具有一定借鑒價值,需要的朋友可以了解下。
    2017-12-12
  • YOLOv5車牌識別實戰(zhàn)教程(五)字符分割與識別

    YOLOv5車牌識別實戰(zhàn)教程(五)字符分割與識別

    這篇文章主要介紹了YOLOv5車牌識別實戰(zhàn)教程(五)字符分割與識別,在這個教程中,我們將一步步教你如何使用YOLOv5進行車牌識別,幫助你快速掌握YOLOv5車牌識別技能,需要的朋友可以參考下
    2023-04-04
  • pandas parse_dates參數(shù)的使用

    pandas parse_dates參數(shù)的使用

    在Pandas中,parse_dates參數(shù)用于將數(shù)據(jù)框中的某列轉(zhuǎn)換為時間類型,而index_col參數(shù)則將某列設(shè)置為索引。通過這兩個參數(shù),可以有效地管理和操作時間序列數(shù)據(jù)。例如,將'Date'列轉(zhuǎn)為時間類型并設(shè)置為索引,可以方便地進行時間序列分析和操作
    2024-09-09
  • PyQT5 實現(xiàn)快捷鍵復(fù)制表格數(shù)據(jù)的方法示例

    PyQT5 實現(xiàn)快捷鍵復(fù)制表格數(shù)據(jù)的方法示例

    這篇文章主要介紹了PyQT5 實現(xiàn)快捷鍵復(fù)制表格數(shù)據(jù)的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-06-06
  • Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務(wù)

    Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務(wù)

    這篇文章主要為大家介紹了Python與xlwings黃金組合處理Excel各種數(shù)據(jù)和自動化任務(wù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>
    2023-12-12
  • 詳解Python中for循環(huán)的使用

    詳解Python中for循環(huán)的使用

    這篇文章主要介紹了Python中for循環(huán)的使用,來自于IBM官方網(wǎng)站技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • Python命名空間詳解

    Python命名空間詳解

    這篇文章主要介紹了Python命名空間詳解,非常重要的概念,需要的朋友可以參考下
    2014-08-08

最新評論