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

how to update config 2.x to 3.x #12307

Open
vipcxj opened this issue Feb 12, 2025 · 2 comments
Open

how to update config 2.x to 3.x #12307

vipcxj opened this issue Feb 12, 2025 · 2 comments
Assignees

Comments

@vipcxj
Copy link

vipcxj commented Feb 12, 2025

I've looked at the docs and changed everything I can, but I'm still getting the error

/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmengine/optim/optimizer/zero_optimizer.py:11: DeprecationWarning: `TorchScript` support for functional optimizers is deprecated and will be removed in a future PyTorch release. Consider using the `torch.compile` optimizer instead.
  from torch.distributed.optim import \
Loads checkpoint by local backend from path: /home/ps/.cache/torch/hub/checkpoints/mmpose_anime-face_hrnetv2.pth
/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmengine/runner/checkpoint.py:347: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  checkpoint = torch.load(filename, map_location=map_location)
/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmpose/apis/inference.py:121: UserWarning: Can not load dataset_meta from the checkpoint or the model config. Use COCO metainfo by default.
  warnings.warn('Can not load dataset_meta from the checkpoint or the '
/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmpose/datasets/datasets/utils.py:102: UserWarning: The metainfo config file "configs/_base_/datasets/coco.py" does not exist. A matched config file "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmpose/.mim/configs/_base_/datasets/coco.py" will be used instead.
  warnings.warn(
Loads checkpoint by local backend from path: /home/ps/.cache/torch/hub/checkpoints/mmdet_anime-face_yolov3.pth
/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmengine/runner/checkpoint.py:347: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  checkpoint = torch.load(filename, map_location=map_location)
Traceback (most recent call last):
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 71, in <module>
    cli.main()
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 501, in main
    run()
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 351, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 310, in run_path
    return _run_module_code(code, init_globals, run_name, pkg_name=pkg_name, script_name=fname)
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 127, in _run_module_code
    _run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name)
  File "/home/ps/.vscode-server/extensions/ms-python.debugpy-2025.0.0/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 118, in _run_code
    exec(code, run_globals)
  File "/home/ps/workspace/projects/mesh-fitter/src/main.py", line 24, in <module>
    ai.detect_face.detect_face(img, output_path="models/base_female_face_with_landmarks.jpg")
  File "/home/ps/workspace/projects/mesh-fitter/src/ai/detect_face.py", line 11, in detect_face
    results = detector(new_image)
  File "/home/ps/workspace/projects/mesh-fitter/src/ai/anime_face_detector/detector.py", line 133, in __call__
    boxes = self._detect_faces(image)
  File "/home/ps/workspace/projects/mesh-fitter/src/ai/anime_face_detector/detector.py", line 73, in _detect_faces
    boxes = inference_detector(self.face_detector, image)[0]
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmdet/apis/inference.py", line 189, in inference_detector
    results = model.test_step(data_)[0]
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmengine/model/base_model/base_model.py", line 145, in test_step
    return self._run_forward(data, mode='predict')  # type: ignore
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmengine/model/base_model/base_model.py", line 361, in _run_forward
    results = self(**data, mode=mode)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmdet/models/detectors/base.py", line 94, in forward
    return self.predict(inputs, data_samples)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmdet/models/detectors/single_stage.py", line 109, in predict
    x = self.extract_feat(batch_inputs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmdet/models/detectors/single_stage.py", line 146, in extract_feat
    x = self.backbone(batch_inputs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmdet/models/backbones/darknet.py", line 157, in forward
    x = cr_block(x)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/mmcv/cnn/bricks/conv_module.py", line 281, in forward
    x = self.conv(x)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 458, in forward
    return self._conv_forward(input, self.weight, self.bias)
  File "/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 454, in _conv_forward
    return F.conv2d(input, weight, bias, self.stride,
TypeError: conv2d() received an invalid combination of arguments - got (list, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:
 * (Tensor input, Tensor weight, Tensor bias = None, tuple of ints stride = 1, tuple of ints padding = 0, tuple of ints dilation = 1, int groups = 1)
      didn't match because some of the arguments have invalid types: (list of [Tensor], Parameter, NoneType, tuple of (int, int), tuple of (int, int), tuple of (int, int), int)
 * (Tensor input, Tensor weight, Tensor bias = None, tuple of ints stride = 1, str padding = "valid", tuple of ints dilation = 1, int groups = 1)
      didn't match because some of the arguments have invalid types: (list of [Tensor], Parameter, NoneType, tuple of (int, int), tuple of (int, int), tuple of (int, int), int)

/home/ps/mambaforge/envs/mesh-fitter/lib/python3.10/tempfile.py:869: ResourceWarning: Implicitly cleaning up <TemporaryDirectory '/tmp/tmppfgq15nb'>
  _warnings.warn(warn_message, ResourceWarning)

yolo3 config:

model = dict(type='YOLOV3',
             backbone=dict(type='Darknet', depth=53, out_indices=(3, 4, 5)),
             neck=dict(type='YOLOV3Neck',
                       num_scales=3,
                       in_channels=[1024, 512, 256],
                       out_channels=[512, 256, 128]),
             bbox_head=dict(type='YOLOV3Head',
                            num_classes=1,
                            in_channels=[512, 256, 128],
                            out_channels=[1024, 512, 256],
                            anchor_generator=dict(type='YOLOAnchorGenerator',
                                                  base_sizes=[[(116, 90),
                                                               (156, 198),
                                                               (373, 326)],
                                                              [(30, 61),
                                                               (62, 45),
                                                               (59, 119)],
                                                              [(10, 13),
                                                               (16, 30),
                                                               (33, 23)]],
                                                  strides=[32, 16, 8]),
                            bbox_coder=dict(type='YOLOBBoxCoder'),
                            featmap_strides=[32, 16, 8]),
             test_cfg=dict(nms_pre=1000,
                           min_bbox_size=0,
                           score_thr=0.05,
                           conf_thr=0.005,
                           nms=dict(type='nms', iou_threshold=0.45),
                           max_per_img=100))
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='Resize', scale=(608, 608), keep_ratio=True),
    dict(
        type='PackDetInputs',
        meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape',
                   'scale_factor')),
]
test_dataloader = dict(
    batch_size=1,
    persistent_workers=True,
    drop_last=False,
    sampler=dict(type='DefaultSampler', shuffle=False),
    dataset=dict(
        type="CocoDataset",
        test_mode=True,
        pipeline=test_pipeline
    )
)

old config:

model = dict(type='YOLOV3',
             backbone=dict(type='Darknet', depth=53, out_indices=(3, 4, 5)),
             neck=dict(type='YOLOV3Neck',
                       num_scales=3,
                       in_channels=[1024, 512, 256],
                       out_channels=[512, 256, 128]),
             bbox_head=dict(type='YOLOV3Head',
                            num_classes=1,
                            in_channels=[512, 256, 128],
                            out_channels=[1024, 512, 256],
                            anchor_generator=dict(type='YOLOAnchorGenerator',
                                                  base_sizes=[[(116, 90),
                                                               (156, 198),
                                                               (373, 326)],
                                                              [(30, 61),
                                                               (62, 45),
                                                               (59, 119)],
                                                              [(10, 13),
                                                               (16, 30),
                                                               (33, 23)]],
                                                  strides=[32, 16, 8]),
                            bbox_coder=dict(type='YOLOBBoxCoder'),
                            featmap_strides=[32, 16, 8]),
             test_cfg=dict(nms_pre=1000,
                           min_bbox_size=0,
                           score_thr=0.05,
                           conf_thr=0.005,
                           nms=dict(type='nms', iou_threshold=0.45),
                           max_per_img=100))
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='MultiScaleFlipAug',
         img_scale=(608, 608),
         flip=False,
         transforms=[
             dict(type='Resize', keep_ratio=True),
             dict(type='RandomFlip'),
             dict(type='Normalize',
                  mean=[0, 0, 0],
                  std=[255.0, 255.0, 255.0],
                  to_rgb=True),
             dict(type='Pad', size_divisor=32),
             dict(type='ImageToTensor', keys=['img']),
             dict(type='Collect', keys=['img'])
         ])
]
data = dict(test=dict(pipeline=test_pipeline))
@sreeharshaparuchur1
Copy link

Following. I'm trying to do the opposite - Go from a config written for MMdet 3.x but use it in code/ a model with weights that follow the MMdet 2.x convention.

Where did you get an MMdet 2.x config from @vipcxj ?

@vipcxj
Copy link
Author

vipcxj commented Feb 13, 2025

@sreeharshaparuchur1 here

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

3 participants