Skip to content

Commit

Permalink
fix #630: Added exception when receiving empty image
Browse files Browse the repository at this point in the history
  • Loading branch information
mpena-vina committed Dec 1, 2021
1 parent 785b268 commit 3ea6282
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 2 additions & 4 deletions mmocr/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ def model_inference(model,

if isinstance(imgs, (list, tuple)):
is_batch = True
if not len(imgs):
if not return_data:
return []
return [], []
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
7 changes: 5 additions & 2 deletions tests/test_apis/test_model_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def test_model_batch_inference_empty_detection(cfg_file):
model = build_model(config_file)

empty_detection = []
results = model_inference(model, empty_detection, batch_mode=True)

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

model_inference(model, empty_detection, batch_mode=True)

0 comments on commit 3ea6282

Please sign in to comment.