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

Commit

Permalink
Improve error message when model name not registered
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrew Ho authored and facebook-github-bot committed Sep 15, 2022
1 parent a34ccc5 commit e27f5d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classy_vision/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_model(config):
"foo": "bar"}` will find a class that was registered as "my_model"
(see :func:`register_model`) and call .from_config on it."""

assert config["name"] in MODEL_REGISTRY, "unknown model"
assert config["name"] in MODEL_REGISTRY, f"unknown model: {config['name']}"
model = MODEL_REGISTRY[config["name"]].from_config(config)
if "heads" in config:
heads = defaultdict(list)
Expand Down
15 changes: 15 additions & 0 deletions test/models_classy_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ def get_model_config(self, use_head):
]
return config

def test_model_bad_name(self):
config = self.get_model_config(use_head=True)
test_bad_name = "__test_bad_name__"
config["name"] = test_bad_name

try:
_ = build_model(config)
except AssertionError as e:
self.assertTrue(
test_bad_name in str(e),
f"expected {test_bad_name} in error message, got {str(e)}",
)
return
self.assertTrue(False, "expected an AssertionError to be thrown")

def test_from_checkpoint(self):
config = get_test_task_config()
for use_head in [True, False]:
Expand Down

0 comments on commit e27f5d8

Please sign in to comment.