Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我在用mmrazor通过yolov5-x蒸馏yolov5-s时候遇到了问题 #644

Open
KungFuPandaPro opened this issue Jun 2, 2024 · 1 comment
Open

Comments

@KungFuPandaPro
Copy link

Checklist

  • I have searched related issues but cannot get the expected help.
  • I have read related documents and don't know what to do.

Describe the question you meet

我使用mmyolo\configs\rtmdet\distillation\kd_s_rtmdet_m_neck_300e_coco.py这个蒸馏的配置文件进行修改提供给yolov5蒸馏使用,但是控制台报错,显示TypeError: optimizer can only optimize Tensors, but one of the params is NoneType

Post related information

这是控制台相关输出
Traceback (most recent call last):
File "D:\python\mmrazor\tools\train.py", line 121, in
main()
File "D:\python\mmrazor\tools\train.py", line 117, in main
runner.train()
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\mmengine\runner\runner.py", line 1734, in train
self.optim_wrapper = self.build_optim_wrapper(self.optim_wrapper)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\mmengine\runner\runner.py", line 1115, in build_optim_wrapper
return build_optim_wrapper(self.model, optim_wrapper)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\mmengine\optim\optimizer\builder.py", line 210, in build_optim_wrapper
optim_wrapper = optim_wrapper_constructor(model)
File "d:\python\mmyolo\mmyolo\engine\optimizers\yolov5_optim_constructor.py", line 129, in call
optimizer = OPTIMIZERS.build(optimizer_cfg)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\mmengine\registry\registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\mmengine\registry\build_functions.py", line 121, in build_from_cfg
obj = obj_cls(**args) # type: ignore
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\torch\optim\sgd.py", line 27, in init
super().init(params, defaults)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\torch\optim\optimizer.py", line 284, in init
self.add_param_group(cast(dict, param_group))
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\torch_compile.py", line 24, in inner
return torch._dynamo.disable(fn, recursive)(*args, **kwargs)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\torch_dynamo\eval_frame.py", line 451, in _fn
return fn(*args, **kwargs)
File "C:\Users\zhan.conda\envs\mmdetection\lib\site-packages\torch\optim\optimizer.py", line 891, in add_param_group
raise TypeError("optimizer can only optimize Tensors, "
TypeError: optimizer can only optimize Tensors, but one of the params is NoneType

这是我的蒸馏配置文件
base=['yolov5_m-v61_syncbn_fast_8xb16-300e_coco.py']
teacher_ckpt = 'D:\python\mmyolo/models/yolov5_x-v61_syncbn_fast_8xb16-300e_coco_20230305_152943-00776a4b.pth'
norm_cfg = dict(type='BN', affine=False, track_running_stats=False)
#mmyolo::yolov5/yolov5_x-v61_syncbn_fast_8xb16-300e_coco.py
model = dict(
delete=True,
scope='mmrazor',
type='FpnTeacherDistill',
architecture=dict(
cfg_path='mmyolo::yolov5/yolov5_s-v61_syncbn_fast_8xb16-300e_coco.py'),
teacher=dict(
cfg_path='mmyolo::yolov5/yolov5_x-v61_syncbn_fast_8xb16-300e_coco.py'),
teacher_ckpt=teacher_ckpt,
distiller=dict(
type='ConfigurableDistiller',
# recorders are used to record various intermediate results during
# the model forward.
student_recorders=dict(
fpn0=dict(type='ModuleOutputs', source='neck.out_layers.0'),
fpn1=dict(type='ModuleOutputs', source='neck.out_layers.1'),
fpn2=dict(type='ModuleOutputs', source='neck.out_layers.2'),
),
teacher_recorders=dict(
fpn0=dict(type='ModuleOutputs', source='neck.out_layers.0'),
fpn1=dict(type='ModuleOutputs', source='neck.out_layers.1'),
fpn2=dict(type='ModuleOutputs', source='neck.out_layers.2')),
# connectors are adaptive layers which usually map teacher's and
# students features to the same dimension.
connectors=dict(
fpn0_s=dict(
type='ConvModuleConnector',
in_channel=128,
out_channel=320,
bias=False,
norm_cfg=norm_cfg,
act_cfg=None),
fpn0_t=dict(
type='NormConnector', in_channels=320, norm_cfg=norm_cfg),
fpn1_s=dict(
type='ConvModuleConnector',
in_channel=256,
out_channel=640,
bias=False,
norm_cfg=norm_cfg,
act_cfg=None),
fpn1_t=dict(
type='NormConnector', in_channels=640, norm_cfg=norm_cfg),
fpn2_s=dict(
type='ConvModuleConnector',
in_channel=512,
out_channel=1280,
bias=False,
norm_cfg=norm_cfg,
act_cfg=None),
fpn2_t=dict(
type='NormConnector', in_channels=1280, norm_cfg=norm_cfg)),
distill_losses=dict(
loss_fpn0=dict(type='ChannelWiseDivergence', loss_weight=1),
loss_fpn1=dict(type='ChannelWiseDivergence', loss_weight=1),
loss_fpn2=dict(type='ChannelWiseDivergence', loss_weight=1)),
# loss_forward_mappings are mappings between distill loss forward
# arguments and records.
loss_forward_mappings=dict(
loss_fpn0=dict(
preds_S=dict(
from_student=True, recorder='fpn0', connector='fpn0_s'),
preds_T=dict(
from_student=False, recorder='fpn0', connector='fpn0_t')),
loss_fpn1=dict(
preds_S=dict(
from_student=True, recorder='fpn1', connector='fpn1_s'),
preds_T=dict(
from_student=False, recorder='fpn1', connector='fpn1_t')),
loss_fpn2=dict(
preds_S=dict(
from_student=True, recorder='fpn2', connector='fpn2_s'),
preds_T=dict(
from_student=False, recorder='fpn2',
connector='fpn2_t')))))

find_unused_parameters = True
[#](url)

[here]
  1. Your train log file if you meet the problem during training.
    [here]
  2. Other code you modified in the mmrazor folder.
    [here]
@ChinaStark
Copy link

snapshot is good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants