Closed coptersack closed 2 months ago
在 __init__.py
文件import
下你新增的backbone
在
__init__.py
文件import
下你新增的backbone
感谢您的解答,但是这一步我也做了的
我看下你怎么注册的; v2版本和v1的实现有点差异
class RepViT(nn.Module):
def __init__(self, cfgs, distillation=False, pretrained=None, init_cfg=None, out_indices=[]):
super(RepViT, self).__init__()
# setting of inverted residual blocks
self.cfgs = cfgs
# building first layer
input_channel = self.cfgs[0][2]
patch_embed = torch.nn.Sequential(Conv2d_BN(3, input_channel // 2, 3, 2, 1), torch.nn.GELU(),
Conv2d_BN(input_channel // 2, input_channel, 3, 2, 1))
layers = [patch_embed]
# building inverted residual blocks
block = RepViTBlock
for k, t, c, use_se, use_hs, s in self.cfgs:
output_channel = _make_divisible(c, 8)
exp_size = _make_divisible(input_channel * t, 8)
layers.append(block(input_channel, exp_size, output_channel, k, s, use_se, use_hs))
input_channel = output_channel
self.features = nn.ModuleList(layers)
self.init_cfg = init_cfg
# assert (self.init_cfg is not None)
self.out_indices = out_indices
self._init_weights()
self = torch.nn.SyncBatchNorm.convert_sync_batchnorm(self)
self.train()
def train(self, mode=True):
"""Convert the model into training mode while keep layers freezed."""
super(RepViT, self).train(mode)
if mode:
for m in self.modules():
if isinstance(m, _BatchNorm):
m.eval()
def forward(self, x):
outs = []
for i, f in enumerate(self.features):
x = f(x)
if i in self.out_indices:
outs.append(x)
assert (len(outs) == 4)
return outs[1:4]
@register
def repvit_m1_1(pretrained=False, distillation=False, init_cfg=None, out_indices=[], **kwargs):
cfgs = [
# k, t, c, SE, HS, s
]
return RepViT(cfgs, init_cfg=init_cfg, pretrained=pretrained, distillation=distillation, out_indices=out_indices)
这是backbone/repvit中的注册代码,config就是在resnet50上加了
RTDETR:
backbone: repvit_m1_1
十分感谢您在百忙之中还帮我解决这些低级问题,哈哈哈哈
更新下注册那行
# v1
@register
# to
# v2
@register()
感谢,已经解决了
十分感谢您的卓越工作,在更换backbone时,我已经将新的backbone通过register注册过了,新的config文件也添加了,加载模型时,core中的workspace中报错显示 Traceback (most recent call last): File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools\train.py", line 71, in
main(args)
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools\train.py", line 35, in main
solver.fit()
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools..\src\solver\det_solver.py", line 20, in fit
self.train()
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools..\src\solver_solver.py", line 68, in train
self._setup()
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools..\src\solver_solver.py", line 35, in _setup
self.model = cfg.model
^^^^^^^^^
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools..\src\core\yaml_config.py", line 36, in model
self._model = create(self.yaml_cfg['model'], self.global_cfg)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Medical_segmentation\Kingmed\RT-DETR-main\rtdetrv2_pytorch\tools..\src\core\workspace.py", line 144, in create
raise ValueError(f'Missing inject config of {_k}.')
ValueError: Missing inject config of repvit_m2_3.
不知道是哪里缺少了步骤或者哪里出了问题,希望您百忙之余可以帮我解答