Skip to content

Conversation

@robotrapta
Copy link
Member

@robotrapta robotrapta commented Nov 12, 2022

Lets you pass in numpy arrays to submit_image_query. This isn't too hard. But we don't want to require numpy to be installed for it to work. That's also not too hard. But getting idiomatic type-hinting to work when you might or might not have numpy installed - that took some effort. Built some fancy fake-importing to do this. There's a TODO in it to give better error messages, but it all works.

Also set up a big test matrix so that we test the SDK with and without numpy, with and without PIL/pillow, and on lots of different versions. Did a good amount of manual verification to ensure that the right tests are being run/skipped in each case.

Fixes #21

@robotrapta robotrapta marked this pull request as draft November 12, 2022 19:13
@robotrapta robotrapta marked this pull request as ready for review November 12, 2022 20:06
@robotrapta
Copy link
Member Author

Okay that was quite a process to get this all built and properly tested. But I think it's in decent shape now.

# So the efficiency argument has its limits
# Failing slow is clearer about what's going on.
# This is pretty unambiguous, so we're going with it for now.
fail-fast: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! Diagnosing a failed run quickly is much more important than seeing a failed run quickly.

else:
raise TypeError(
"Unsupported type for image. We only support JPEG images specified through a filename, bytes, BytesIO, or BufferedReader object."
"Unsupported type for image. We only support numpy arrays (3,W,H) or JPEG images specified through a filename, bytes, BytesIO, or BufferedReader object."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a world where we expose an error with "np" to the end user? It might be better to be explicit (numpy) everywhere. As someone might not know that np==numpy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's pretty universal to import numpy as np.

Copy link
Member

@sunildkumar sunildkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm - reducing the number of pain points for a first time user rocks :)

Copy link
Contributor

@michael-groundlight michael-groundlight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a win for customers, even though it's a little funky.

Comment on lines +46 to +53
- name: install numpy
if: matrix.install_numpy
run: |
poetry run pip install numpy
- name: install pillow
if: matrix.install_pillow
run: |
poetry run pip install pillow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the poetry-native way to accomplish this would be "optional groups" (In v1.2+ https://python-poetry.org/docs/managing-dependencies/#optional-groups, or "extras" in v1.1: https://python-poetry.org/docs/1.1/pyproject#extras).

@robotrapta robotrapta merged commit 234e913 into main Nov 17, 2022
@robotrapta robotrapta deleted the numpy-images branch November 17, 2022 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability send image as numpy array

4 participants