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

TypeError: __init__() got an unexpected keyword argument 'style' #3746

Open
WHUThcz opened this issue Jul 23, 2024 · 2 comments
Open

TypeError: __init__() got an unexpected keyword argument 'style' #3746

WHUThcz opened this issue Jul 23, 2024 · 2 comments

Comments

@WHUThcz
Copy link

WHUThcz commented Jul 23, 2024

I change the backbone of PVT
config

07/23 15:14:37 - mmengine - INFO - Config:
checkpoint = 'work_dirs/fpn/max_acc.pth'
crop_size = (
 512,
 512,
)
data_preprocessor = dict(
 bgr_to_rgb=True,
 mean=[
     123.675,
     116.28,
     103.53,
 ],
 pad_val=0,
 seg_pad_val=255,
 size=(
     512,
     512,
 ),
 std=[
     58.395,
     57.12,
     57.375,
 ],
 type='SegDataPreProcessor')
data_root = 'data/VOCdevkit/VOC2012'
dataset_type = 'PascalVOCDataset'
default_hooks = dict(
 checkpoint=dict(by_epoch=False, interval=2000, type='CheckpointHook'),
 logger=dict(interval=50, log_metric_by_epoch=False, type='LoggerHook'),
 param_scheduler=dict(type='ParamSchedulerHook'),
 sampler_seed=dict(type='DistSamplerSeedHook'),
 timer=dict(type='IterTimerHook'),
 visualization=dict(type='SegVisualizationHook'))
default_scope = 'mmseg'
env_cfg = dict(
 cudnn_benchmark=True,
 dist_cfg=dict(backend='nccl'),
 mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0))
img_ratios = [
 0.5,
 0.75,
 1.0,
 1.25,
 1.5,
 1.75,
]
launcher = 'pytorch'
load_from = 'work_dirs/fpn/max_acc.pth'
log_level = 'INFO'
log_processor = dict(by_epoch=False)
model = dict(
 backbone=dict(
     init_cfg=dict(
         checkpoint='work_dirs/fpn/max_acc.pth', type='Pretrained'),
     style='pytorch',
     type='fpvt_tiny'),
 data_preprocessor=dict(
     bgr_to_rgb=True,
     mean=[
         123.675,
         116.28,
         103.53,
     ],
     pad_val=0,
     seg_pad_val=255,
     size=(
         512,
         512,
     ),
     std=[
         58.395,
         57.12,
         57.375,
     ],
     type='SegDataPreProcessor'),
 decode_head=dict(
     align_corners=False,
     channels=128,
     dropout_ratio=0.1,
     feature_strides=[
         4,
         8,
         16,
         32,
     ],
     in_channels=[
         256,
         256,
         256,
         256,
     ],
     in_index=[
         0,
         1,
         2,
         3,
     ],
     loss_decode=dict(
         loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=False),
     norm_cfg=dict(requires_grad=True, type='SyncBN'),
     num_classes=21,
     type='FPNHead'),
 neck=dict(
     in_channels=[
         64,
         128,
         320,
         512,
     ],
     num_outs=4,
     out_channels=256,
     type='FPN'),
 pretrained=True,
 test_cfg=dict(mode='whole'),
 train_cfg=dict(),
 type='EncoderDecoder')
norm_cfg = dict(requires_grad=True, type='SyncBN')
optim_wrapper = dict(
 optimizer=dict(
     betas=(
         0.9,
         0.999,
     ), lr=0.004, type='AdamW', weight_decay=0.01),
 paramwise_cfg=dict(
     custom_keys=dict(
         head=dict(lr_mult=10.0),
         norm=dict(decay_mult=0.0),
         pos_block=dict(decay_mult=0.0))),
 type='OptimWrapper')
optimizer = dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0005)
param_scheduler = [
 dict(
     begin=0, by_epoch=False, end=1500, start_factor=1e-06,
     type='LinearLR'),
 dict(
     begin=1500,
     by_epoch=False,
     end=320000,
     eta_min=0.0,
     power=0.9,
     type='PolyLR'),
]
resume = False
test_cfg = dict(type='TestLoop')
test_dataloader = dict(
 batch_size=1,
 dataset=dict(
     ann_file='ImageSets/Segmentation/val.txt',
     data_prefix=dict(
         img_path='JPEGImages', seg_map_path='SegmentationClass'),
     data_root='data/VOCdevkit/VOC2012',
     pipeline=[
         dict(type='LoadImageFromFile'),
         dict(keep_ratio=True, scale=(
             2048,
             512,
         ), type='Resize'),
         dict(type='LoadAnnotations'),
         dict(type='PackSegInputs'),
     ],
     reduce_zero_label=True,
     type='PascalVOCDataset'),
 num_workers=4,
 persistent_workers=True,
 sampler=dict(shuffle=False, type='DefaultSampler'))
test_evaluator = dict(
 iou_metrics=[
     'mIoU',
 ], type='IoUMetric')
test_pipeline = [
 dict(type='LoadImageFromFile'),
 dict(keep_ratio=True, scale=(
     2048,
     512,
 ), type='Resize'),
 dict(type='LoadAnnotations'),
 dict(type='PackSegInputs'),
]
train_cfg = dict(max_iters=20000, type='IterBasedTrainLoop', val_interval=2000)
train_dataloader = dict(
 batch_size=8,
 dataset=dict(
     ann_file='ImageSets/Segmentation/train.txt',
     data_prefix=dict(
         img_path='JPEGImages', seg_map_path='SegmentationClass'),
     data_root='data/VOCdevkit/VOC2012',
     pipeline=[
         dict(type='LoadImageFromFile'),
         dict(type='LoadAnnotations'),
         dict(
             keep_ratio=True,
             ratio_range=(
                 0.5,
                 2.0,
             ),
             scale=(
                 2048,
                 512,
             ),
             type='RandomResize'),
         dict(
             cat_max_ratio=0.75, crop_size=(
                 512,
                 512,
             ), type='RandomCrop'),
         dict(prob=0.5, type='RandomFlip'),
         dict(type='PhotoMetricDistortion'),
         dict(type='PackSegInputs'),
     ],
     reduce_zero_label=True,
     type='PascalVOCDataset'),
 num_workers=2,
 persistent_workers=True,
 sampler=dict(shuffle=True, type='InfiniteSampler'))
train_pipeline = [
 dict(type='LoadImageFromFile'),
 dict(type='LoadAnnotations'),
 dict(
     keep_ratio=True,
     ratio_range=(
         0.5,
         2.0,
     ),
     scale=(
         2048,
         512,
     ),
     type='RandomResize'),
 dict(cat_max_ratio=0.75, crop_size=(
     512,
     512,
 ), type='RandomCrop'),
 dict(prob=0.5, type='RandomFlip'),
 dict(type='PhotoMetricDistortion'),
 dict(type='PackSegInputs'),
]
tta_model = dict(type='SegTTAModel')
tta_pipeline = [
 dict(backend_args=None, type='LoadImageFromFile'),
 dict(
     transforms=[
         [
             dict(keep_ratio=True, scale_factor=0.5, type='Resize'),
             dict(keep_ratio=True, scale_factor=0.75, type='Resize'),
             dict(keep_ratio=True, scale_factor=1.0, type='Resize'),
             dict(keep_ratio=True, scale_factor=1.25, type='Resize'),
             dict(keep_ratio=True, scale_factor=1.5, type='Resize'),
             dict(keep_ratio=True, scale_factor=1.75, type='Resize'),
         ],
         [
             dict(direction='horizontal', prob=0.0, type='RandomFlip'),
             dict(direction='horizontal', prob=1.0, type='RandomFlip'),
         ],
         [
             dict(type='LoadAnnotations'),
         ],
         [
             dict(type='PackSegInputs'),
         ],
     ],
     type='TestTimeAug'),
]
val_cfg = dict(type='ValLoop')
val_dataloader = dict(
 batch_size=1,
 dataset=dict(
     ann_file='ImageSets/Segmentation/val.txt',
     data_prefix=dict(
         img_path='JPEGImages', seg_map_path='SegmentationClass'),
     data_root='data/VOCdevkit/VOC2012',
     pipeline=[
         dict(type='LoadImageFromFile'),
         dict(keep_ratio=True, scale=(
             2048,
             512,
         ), type='Resize'),
         dict(type='LoadAnnotations'),
         dict(type='PackSegInputs'),
     ],
     reduce_zero_label=True,
     type='PascalVOCDataset'),
 num_workers=4,
 persistent_workers=True,
 sampler=dict(shuffle=False, type='DefaultSampler'))
val_evaluator = dict(
 iou_metrics=[
     'mIoU',
 ], type='IoUMetric')
vis_backends = [
 dict(type='LocalVisBackend'),
]
visualizer = dict(
 name='visualizer',
 type='SegLocalVisualizer',
 vis_backends=[
     dict(type='LocalVisBackend'),
 ])
work_dir = './work_dirs/fpn_fpvt_t_pascal_voc12_40k'

the command

bash tools/dist_train.sh configs/fpvt/fpn_fpvt_t_pascal_voc12_40k.py 2

I have previously used this model for image classification tasks on ImageNet1k in the same environment. Now, I want to transfer the model weights to mmsegmentation for training on segmentation tasks.

Environment

sys.platform: linux
Python: 3.8.18 (default, Sep 11 2023, 13:40:15) [GCC 11.2.0]
CUDA available: True
numpy_random_seed: 2147483648
GPU 0,1: NVIDIA GeForce RTX 2080 Ti
CUDA_HOME: :/home/zhangbo/cuda-10.2
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.12.1+cu102
PyTorch compiling details: PyTorch built with:
- GCC 7.3
- C++ Version: 201402
- Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX2
- CUDA Runtime 10.2
- NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70
- CuDNN 7.6.5
- Magma 2.5.2
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.2, CUDNN_VERSION=7.6.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.12.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

TorchVision: 0.13.1+cu102
OpenCV: 4.9.0
MMEngine: 0.10.2
MMSegmentation: 1.2.2+c685fe6

**Error traceback**

```none
Traceback (most recent call last):
File "tools/train.py", line 105, in <module>
 main()
File "tools/train.py", line 94, in main
 runner = Runner.from_cfg(cfg)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 462, in from_cfg
 runner = cls(
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 429, in __init__
 self.model = self.build_model(model)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 836, in build_model
 model = MODELS.build(model)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/registry.py", line 570, in build
 return self.build_func(cfg, *args, **kwargs, registry=self)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
 return build_from_cfg(cfg, registry, default_args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
 obj = obj_cls(**args)  # type: ignore
File "/data/datas/hcz/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 89, in __init__
 self.backbone = MODELS.build(backbone)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/registry.py", line 570, in build
 return self.build_func(cfg, *args, **kwargs, registry=self)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
 return build_from_cfg(cfg, registry, default_args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
 obj = obj_cls(**args)  # type: ignore
File "/data/datas/hcz/mmsegmentation/mmseg/models/backbones/fpvt.py", line 662, in fpvt_tiny
 model = PyramidVisionTransformerV2(
TypeError: __init__() got an unexpected keyword argument 'style'
Traceback (most recent call last):
File "tools/train.py", line 105, in <module>
 main()
File "tools/train.py", line 94, in main
 runner = Runner.from_cfg(cfg)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 462, in from_cfg
 runner = cls(
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 429, in __init__
 self.model = self.build_model(model)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/runner/runner.py", line 836, in build_model
 model = MODELS.build(model)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/registry.py", line 570, in build
 return self.build_func(cfg, *args, **kwargs, registry=self)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
 return build_from_cfg(cfg, registry, default_args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
 obj = obj_cls(**args)  # type: ignore
File "/data/datas/hcz/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 89, in __init__
 self.backbone = MODELS.build(backbone)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/registry.py", line 570, in build
 return self.build_func(cfg, *args, **kwargs, registry=self)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
 return build_from_cfg(cfg, registry, default_args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
 obj = obj_cls(**args)  # type: ignore
File "/data/datas/hcz/mmsegmentation/mmseg/models/backbones/fpvt.py", line 662, in fpvt_tiny
 model = PyramidVisionTransformerV2(
TypeError: __init__() got an unexpected keyword argument 'style'
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 5205) of binary: /data/datas/hcz/envs/mmseg/bin/python
Traceback (most recent call last):
File "/data/datas/hcz/envs/mmseg/lib/python3.8/runpy.py", line 194, in _run_module_as_main
 return _run_code(code, main_globals, None,
File "/data/datas/hcz/envs/mmseg/lib/python3.8/runpy.py", line 87, in _run_code
 exec(code, run_globals)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/launch.py", line 193, in <module>
 main()
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/launch.py", line 189, in main
 launch(args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/launch.py", line 174, in launch
 run(args)
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/run.py", line 752, in run
 elastic_launch(
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 131, in __call__
 return launch_agent(self._config, self._entrypoint, list(args))
File "/data/datas/hcz/envs/mmseg/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 245, in launch_agent
 raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError: 
============================================================
tools/train.py FAILED
------------------------------------------------------------
Failures:
[1]:
time      : 2024-07-23_15:14:42
host      : ubuntu
rank      : 1 (local_rank: 1)
exitcode  : 1 (pid: 5206)
error_file: <N/A>
traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
time      : 2024-07-23_15:14:42
host      : ubuntu
rank      : 0 (local_rank: 0)
exitcode  : 1 (pid: 5205)
error_file: <N/A>
traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================
@AI-Tianlong
Copy link
Contributor

Hello, fpvt是你自己实现的嘛,看起来在config里,你给了一个 style='pytorch'的参数,因为我看不到fpvt的模型定义,不知道这个style是干什么,能提供更多地信息嘛?或者你在config里,将 style='pytorch' 注释掉呢?

@WHUThcz
Copy link
Author

WHUThcz commented Jul 23, 2024

Hello, fpvt是你自己实现的嘛,看起来在config里,你给了一个 style='pytorch'的参数,因为我看不到fpvt的模型定义,不知道这个style是干什么,能提供更多地信息嘛?或者你在config里,将 style='pytorch' 注释掉呢?

我刚看了一下,我在运行的config文件中没有找到style='pytorch'这一行参数,但是我在执行了之前的command命令之后所产生的work_dir文件中找到了包含所有参数的config文件,其中包含这一行参数,删去之后执行它发现是可以运行的。万分感谢!

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