While modificating mmaction_tutorial.ipynb for my needs got an error:
TypeError: FormatCode() got an unexpected keyword argument 'verify'
from 2 places in code:
print(f'Config:\n{cfg.pretty_text}')
runner = Runner.from_cfg(cfg)
Reproduces the problem - code sample
from mmengine import Config
from mmengine.runner import set_random_seed
cfg = Config.fromfile('configs/tsn_imagenet-pretrained-r50_8xb32-1x1x3-100e_kinetics400-rgb.py')
# Modify dataset type and path
cfg.data_root = 'datasets/synth_drone_operator/train/'
cfg.data_root_val = 'datasets/synth_drone_operator/val/'
cfg.ann_file_train = 'datasets/synth_drone_operator/synth_drone_operator_train_video.txt'
cfg.ann_file_val = 'datasets/synth_drone_operator/synth_drone_operator_val_video.txt'
cfg.test_dataloader.dataset.ann_file = 'datasets/synth_drone_operator/synth_drone_operator_val_video.txt'
cfg.test_dataloader.dataset.data_prefix.video = 'datasets/synth_drone_operator/val/'
cfg.train_dataloader.dataset.ann_file = 'datasets/synth_drone_operator/synth_drone_operator_train_video.txt'
cfg.train_dataloader.dataset.data_prefix.video = 'datasets/synth_drone_operator/train/'
cfg.val_dataloader.dataset.ann_file = 'datasets/synth_drone_operator/synth_drone_operator_val_video.txt'
cfg.val_dataloader.dataset.data_prefix.video = 'datasets/synth_drone_operator/val/'
# Modify num classes of the model in cls_head
cfg.model.cls_head.num_classes = 8
# We can use the pre-trained TSN model
cfg.load_from = 'models/tsn_imagenet-pretrained-r50_8xb32-1x1x8-100e_kinetics400-rgb_20220906-2692d16c.pth'
# Set up working dir to save files and logs.
cfg.work_dir = 'working_directory'
# The original learning rate (LR) is set for 8-GPU training.
# We divide it by 8 since we only use one GPU.
cfg.train_dataloader.batch_size = cfg.train_dataloader.batch_size // 16
cfg.val_dataloader.batch_size = cfg.val_dataloader.batch_size // 16
cfg.optim_wrapper.optimizer.lr = cfg.optim_wrapper.optimizer.lr / 8 / 16
cfg.train_cfg.max_epochs = 10
cfg.train_dataloader.num_workers = 2
cfg.val_dataloader.num_workers = 2
cfg.test_dataloader.num_workers = 2
# We can initialize the logger for training and have a look
# at the final config used for training
print(f'Config:\n{cfg.pretty_text}')
import os.path as osp
import mmengine
from mmengine.runner import Runner
# Create work_dir
mmengine.mkdir_or_exist(osp.abspath(cfg.work_dir))
# build the runner from config
runner = Runner.from_cfg(cfg)
# start training
runner.train()
Reproduces the problem - command or script
No response
Reproduces the problem - error message
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[10], [line 40](vscode-notebook-cell:?execution_count=10&line=40)
[36](vscode-notebook-cell:?execution_count=10&line=36) cfg.test_dataloader.num_workers = 2
[38](vscode-notebook-cell:?execution_count=10&line=38) # We can initialize the logger for training and have a look
[39](vscode-notebook-cell:?execution_count=10&line=39) # at the final config used for training
---> [40](vscode-notebook-cell:?execution_count=10&line=40) print(f'Config:\n{cfg.pretty_text}')
File ~/.local/lib/python3.10/site-packages/mmengine/config/config.py:883, in Config.pretty_text(self)
[878](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:878) # copied from setup.cfg
[879](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:879) yapf_style = dict(
[880](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:880) based_on_style='pep8',
[881](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:881) blank_line_before_nested_class_or_def=True,
[882](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:882) split_before_expression_after_opening_paren=True)
--> [883](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:883) text, _ = FormatCode(text, style_config=yapf_style, verify=True)
[885](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:885) return text
TypeError: FormatCode() got an unexpected keyword argument 'verify'
and another, as I describe above:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], [line 9](vscode-notebook-cell:?execution_count=9&line=9)
[6](vscode-notebook-cell:?execution_count=9&line=6) mmengine.mkdir_or_exist(osp.abspath(cfg.work_dir))
[8](vscode-notebook-cell:?execution_count=9&line=8) # build the runner from config
----> [9](vscode-notebook-cell:?execution_count=9&line=9) runner = Runner.from_cfg(cfg)
[11](vscode-notebook-cell:?execution_count=9&line=11) # start training
[12](vscode-notebook-cell:?execution_count=9&line=12) runner.train()
File ~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:439, in Runner.from_cfg(cls, cfg)
[429](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:429) """Build a runner from config.
[430](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:430)
[431](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:431) Args:
(...)
[436](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:436) Runner: A runner build from ``cfg``.
[437](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:437) """
[438](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:438) cfg = copy.deepcopy(cfg)
--> [439](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:439) runner = cls(
[440](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:440) model=cfg['model'],
[441](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:441) work_dir=cfg['work_dir'],
[442](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:442) train_dataloader=cfg.get('train_dataloader'),
[443](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:443) val_dataloader=cfg.get('val_dataloader'),
[444](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:444) test_dataloader=cfg.get('test_dataloader'),
[445](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:445) train_cfg=cfg.get('train_cfg'),
[446](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:446) val_cfg=cfg.get('val_cfg'),
[447](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:447) test_cfg=cfg.get('test_cfg'),
[448](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:448) auto_scale_lr=cfg.get('auto_scale_lr'),
[449](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:449) optim_wrapper=cfg.get('optim_wrapper'),
[450](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:450) param_scheduler=cfg.get('param_scheduler'),
[451](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:451) val_evaluator=cfg.get('val_evaluator'),
[452](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:452) test_evaluator=cfg.get('test_evaluator'),
[453](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:453) default_hooks=cfg.get('default_hooks'),
[454](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:454) custom_hooks=cfg.get('custom_hooks'),
[455](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:455) data_preprocessor=cfg.get('data_preprocessor'),
[456](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:456) load_from=cfg.get('load_from'),
[457](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:457) resume=cfg.get('resume', False),
[458](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:458) launcher=cfg.get('launcher', 'none'),
[459](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:459) env_cfg=cfg.get('env_cfg'), # type: ignore
[460](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:460) log_processor=cfg.get('log_processor'),
[461](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:461) log_level=cfg.get('log_level', 'INFO'),
[462](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:462) visualizer=cfg.get('visualizer'),
[463](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:463) default_scope=cfg.get('default_scope', 'mmengine'),
[464](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:464) randomness=cfg.get('randomness', dict(seed=None)),
[465](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:465) experiment_name=cfg.get('experiment_name'),
[466](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:466) cfg=cfg,
[467](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:467) )
[469](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:469) return runner
File ~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:380, in Runner.__init__(self, model, work_dir, train_dataloader, val_dataloader, test_dataloader, train_cfg, val_cfg, test_cfg, auto_scale_lr, optim_wrapper, param_scheduler, val_evaluator, test_evaluator, default_hooks, custom_hooks, data_preprocessor, load_from, resume, launcher, env_cfg, log_processor, log_level, visualizer, default_scope, randomness, experiment_name, cfg)
[377](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:377) self.logger = self.build_logger(log_level=log_level)
[379](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:379) # Collect and log environment information.
--> [380](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:380) self._log_env(env_cfg)
[382](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:382) # Build `message_hub` for communication among components.
[383](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:383) # `message_hub` can store log scalars (loss, learning rate) and
[384](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:384) # runtime information (iter and epoch). Those components that do not
(...)
[389](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:389) # current epoch by `cur_epoch = self.message_hub.get_info('epoch')`.
[390](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:390) # See `MessageHub` and `ManagerMixin` for more details.
[391](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:391) self.message_hub = self.build_message_hub()
File ~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2300, in Runner._log_env(self, env_cfg)
[2294](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2294) self.logger.info('\n' + dash_line + '\nSystem environment:' +
[2295](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2295) env_info + '\n'
[2296](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2296) '\nRuntime environment:' + runtime_env_info + '\n' +
[2297](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2297) dash_line + '\n')
[2299](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2299) if self.cfg._cfg_dict:
-> [2300](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/runner/runner.py:2300) self.logger.info(f'Config:\n{self.cfg.pretty_text}')
File ~/.local/lib/python3.10/site-packages/mmengine/config/config.py:883, in Config.pretty_text(self)
[878](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:878) # copied from setup.cfg
[879](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:879) yapf_style = dict(
[880](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:880) based_on_style='pep8',
[881](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:881) blank_line_before_nested_class_or_def=True,
[882](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:882) split_before_expression_after_opening_paren=True)
--> [883](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:883) text, _ = FormatCode(text, style_config=yapf_style, verify=True)
[885](https://vscode-remote+10-002e127-002e0-002e39-003a8400.vscode-resource.vscode-cdn.net/wd/mmaction2_drone/~/.local/lib/python3.10/site-packages/mmengine/config/config.py:885) return text
TypeError: FormatCode() got an unexpected keyword argument 'verify'
Additional information
I'm using my own dataset, but prepared like tutorial says
Branch
main branch (1.x version, such as
v1.0.0
, ordev-1.x
branch)Prerequisite
Environment
sys.platform: linux Python: 3.10.11 (main, Apr 20 2023, 19:02:41) [GCC 11.2.0] CUDA available: True numpy_random_seed: 2147483648 GPU 0: NVIDIA GeForce RTX 4090 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.7, V11.7.99 GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 PyTorch: 2.0.1 PyTorch compiling details: PyTorch built with:
TorchVision: 0.15.2 OpenCV: 4.10.0 MMEngine: 0.7.2 MMAction2: 1.2.0+32e1aec MMCV: 2.0.0 MMDetection: 3.0.0 MMPose: 1.0.0
Describe the bug
While modificating mmaction_tutorial.ipynb for my needs got an error:
TypeError: FormatCode() got an unexpected keyword argument 'verify'
from 2 places in code:
print(f'Config:\n{cfg.pretty_text}')
runner = Runner.from_cfg(cfg)
Reproduces the problem - code sample
actually from:
print(f'Config:\n{cfg.pretty_text}')
and from this:
Reproduces the problem - command or script
No response
Reproduces the problem - error message
and another, as I describe above:
Additional information
I'm using my own dataset, but prepared like tutorial says
Can anyone help me?