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

fix #630: Add input size check to model_inference #633

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mmocr/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def model_inference(model,

if isinstance(imgs, (list, tuple)):
is_batch = True
if len(imgs) == 0:
raise Exception('empty imgs provided, please check and try again')
if not isinstance(imgs[0], (np.ndarray, str)):
raise AssertionError('imgs must be strings or numpy arrays')

Expand Down
17 changes: 17 additions & 0 deletions tests/test_apis/test_model_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,20 @@ def test_model_batch_inference_recog(cfg_file):
results = model_inference(model, [img, img], batch_mode=True)

assert len(results) == 2


@pytest.mark.parametrize(
'cfg_file',
['../configs/textdet/psenet/psenet_r50_fpnf_600e_icdar2017.py'])
def test_model_batch_inference_empty_detection(cfg_file):
tmp_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
config_file = os.path.join(tmp_dir, cfg_file)
model = build_model(config_file)

empty_detection = []

with pytest.raises(
Exception,
match='empty imgs provided, please check and try again'):

model_inference(model, empty_detection, batch_mode=True)