Unverified Commit 3d229dba authored by Wang Xinjiang's avatar Wang Xinjiang Committed by GitHub
Browse files

Add more error info in build_from_cfg (#834)

* Add more Error info in building from config

* Add more Error info in building from config

* change error info
parent 1c2e665a
...@@ -175,5 +175,8 @@ def build_from_cfg(cfg, registry, default_args=None): ...@@ -175,5 +175,8 @@ def build_from_cfg(cfg, registry, default_args=None):
else: else:
raise TypeError( raise TypeError(
f'type must be a str or valid type, but got {type(obj_type)}') f'type must be a str or valid type, but got {type(obj_type)}')
try:
return obj_cls(**args) return obj_cls(**args)
except Exception as e:
# Normal TypeError does not print class name.
raise type(e)(f'{obj_cls.__name__}: {e}')
...@@ -221,3 +221,8 @@ def test_build_from_cfg(): ...@@ -221,3 +221,8 @@ def test_build_from_cfg():
with pytest.raises(TypeError): with pytest.raises(TypeError):
cfg = dict(type='ResNet', depth=50) cfg = dict(type='ResNet', depth=50)
model = mmcv.build_from_cfg(cfg, BACKBONES, default_args=0) model = mmcv.build_from_cfg(cfg, BACKBONES, default_args=0)
# incorrect arguments
with pytest.raises(TypeError):
cfg = dict(type='ResNet', non_existing_arg=50)
model = mmcv.build_from_cfg(cfg, BACKBONES)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment