mirror of
https://github.com/serengil/deepface.git
synced 2025-06-06 19:45:21 +00:00
failure to decode an io object as an image raises an exception
This commit is contained in:
parent
f9af73c1c7
commit
242bd3eb84
@ -146,6 +146,8 @@ def load_image_from_io_object(obj: IO[bytes]) -> np.ndarray:
|
||||
try:
|
||||
nparr = np.frombuffer(obj.read(), np.uint8)
|
||||
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
||||
if img is None:
|
||||
raise ValueError("Failed to decode image")
|
||||
return img
|
||||
finally:
|
||||
if not seekable:
|
||||
|
@ -1,6 +1,7 @@
|
||||
# built-in dependencies
|
||||
import io
|
||||
import cv2
|
||||
import pytest
|
||||
|
||||
# project dependencies
|
||||
from deepface import DeepFace
|
||||
@ -31,6 +32,10 @@ def test_standard_represent_with_io_object():
|
||||
no_seek_io_embedding_objs = DeepFace.represent(io_obj)
|
||||
assert default_embedding_objs == no_seek_io_embedding_objs
|
||||
|
||||
# Confirm non-image io objects raise exceptions
|
||||
with pytest.raises(ValueError, match='Failed to decode image'):
|
||||
DeepFace.represent(io.BytesIO(open(__file__, 'rb').read()))
|
||||
|
||||
logger.info("✅ test standard represent with io object function done")
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user