Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit e27f5d8

Browse files
Andrew Hofacebook-github-bot
authored andcommitted
Improve error message when model name not registered
Summary: This assertion masks the missing model name from the error message, which makes it hard to debug. This diff adds the name into the error. Differential Revision: D39513464 fbshipit-source-id: 41ba0651832cd72f5545551c24f9faec5ff2bc57
1 parent a34ccc5 commit e27f5d8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

classy_vision/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def build_model(config):
7878
"foo": "bar"}` will find a class that was registered as "my_model"
7979
(see :func:`register_model`) and call .from_config on it."""
8080

81-
assert config["name"] in MODEL_REGISTRY, "unknown model"
81+
assert config["name"] in MODEL_REGISTRY, f"unknown model: {config['name']}"
8282
model = MODEL_REGISTRY[config["name"]].from_config(config)
8383
if "heads" in config:
8484
heads = defaultdict(list)

test/models_classy_model_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ def get_model_config(self, use_head):
8383
]
8484
return config
8585

86+
def test_model_bad_name(self):
87+
config = self.get_model_config(use_head=True)
88+
test_bad_name = "__test_bad_name__"
89+
config["name"] = test_bad_name
90+
91+
try:
92+
_ = build_model(config)
93+
except AssertionError as e:
94+
self.assertTrue(
95+
test_bad_name in str(e),
96+
f"expected {test_bad_name} in error message, got {str(e)}",
97+
)
98+
return
99+
self.assertTrue(False, "expected an AssertionError to be thrown")
100+
86101
def test_from_checkpoint(self):
87102
config = get_test_task_config()
88103
for use_head in [True, False]:

0 commit comments

Comments
 (0)