Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
load_image now accepts file objects that support being read #1423
load_image now accepts file objects that support being read #1423
Changes from 1 commit
4f0fa6e
f9af73c
242bd3e
8c5a235
39173b7
f3da544
7112766
86fa2df
e4cba05
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if i pass a text file as
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that'll work as
io.BytesIO
supports.read
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not okay then, we should be able to pass only image files to deepface functionalities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I'm sorry, I misunderstood what you were asking.
An error would be raised by
np.frombuffer(obj.read(), np.uint8)
orcv2.imdecode(nparr, cv2.IMREAD_COLOR)
, just as if you were trying to pass any other non-supported filetype as a string/filepath toload_image
.I only meant it would pass the
hasattr(img, "read") and callable(img.read)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to call
load_image_from_io_object
with requirements.txt but it didn't throw any exceptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I had been following how
load_image_from_web
handled malformed images, but, if you want to raise the error in the function, I could updateload_image_from_io_object
to raise a ValueError ifcv2.imdecode
returnsNone
like howload_image_from_file_storage
is currently implemented.It does appear modules in
deepface.modules
all already doNone
checks when loading theimg_path
, whichload_image_from_io_object
does follow in convention.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please raise an error if it is not an image?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_image_from_io_object
now raises aValueException
ifcv2.imdecode
returnsNone
for objects that aren't images, which is in line with howload_image_from_file_storage
handles non-image objects.