简介
BestYOLO:https://github.com/WangRongsheng/BestYOLO
BestYOLO是一个以科研和竞赛为导向的最好的YOLO实践框架!
目前BestYOLO是一个完全基于YOLOv5 v7.0 进行改进的开源库,该库将始终秉持以落地应用为导向,以轻便化使用为宗旨,简化各种模块的改进。目前已经集成了基于torchvision.models 模型为Backbone的YOLOv5目标检测算法,同时也将逐渐开源更多YOLOv5应用程序。
替换为ResNet50模型
修改common.py
在最后添加:
from torchvision import models
'''
模型:resnet50
'''
class resnet501(nn.Module):
def __init__(self, ignore) -> None:
super().__init__()
model = models.resnet50(pretrained=True)
modules = list(model.children())
modules = modules[:6]
self.model = nn.Sequential(*modules)
def forward(self, x):
return self.model(x)
class resnet502(nn.Module):
def __init__(self, ignore) -> None:
super().__init__()
model = models.resnet50(pretrained=True)
modules = list(model.children())
modules = modules[6]
self.model = nn.Sequential(*modules)
def forward(self, x):
return self.model(x)
class resnet503(nn.Module):
def __init__(self, ignore) -> None:
super().__init__()
model = models.resnet50(pretrained=True)
modules = list(model.children())
modules = modules[7]
self.model = nn.Sequential(*modules)
def forward(self, x):
return self.model(x)
如果不需要开启预训练权重,删除pretrained=True
即可。
修改yolo.py
在elif m is Expand:
下面添加:文章来源:https://www.toymoban.com/news/detail-451864.html
elif m is resnet501 or m is resnet502 or m is resnet503:
c2 = args[0]
修改.yaml配置
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Parameters
nc: 2 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.25 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, resnet501, [512]], # 0
[-1, 1, resnet502, [1024]], # 1
[-1, 1, resnet503, [2048]], # 2
[-1, 1, SPPF, [1024, 5]], # 3
]
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 1], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 7
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 0], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 11 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 7], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 14 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 3], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 17 (P5/32-large)
[[11, 14, 17], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]
.yaml
配置文件中的depth_multiple
和width_multiple
可以同时设置为1.0
试试,说不定会有不错的效果。文章来源地址https://www.toymoban.com/news/detail-451864.html
具体指标
models | layers | parameters | model size(MB) |
---|---|---|---|
ResNet50 | 258 | 27560895 | 55.7 |
到了这里,关于YOLOv5改进之替换Backbone为ResNet50的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!