-
Notifications
You must be signed in to change notification settings - Fork 116
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
new: Added jina clip v1 #408
Conversation
86287ef
to
82e2d4b
Compare
aa6be34
to
2de91d5
Compare
height, width = image.height, image.width | ||
|
||
# if the size is larger than the new canvas | ||
if width > size or height > size: |
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.
should not it be if width >= size and height >= size
?
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.
It should be or. Assuming that size=500, width=600, height=400. With or, it will trigger cuz width>size, with and it will not trigger cuz hight <= size (and in theory we want either dimension if higher to be cropped)
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 will happen to the second dimension?
if height and width are 600 and 400, required size is 500, the result shape will be (500, 500)
So, what are those 100 pixels which occur in width? What are their values? Which color was used to fill them?
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.
It turns out that internally, the crop function pads the smaller side with zeros by default and the fill_color is not used if one of the sides > size. I modified the implementation.
image = image.crop((left, top, right, bottom)) | ||
return image | ||
|
||
new_image = Image.new(mode="RGB", size=(size, size), color=fill_color) |
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 we pass a grayscale 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.
In our post processor, the first operation is to change the image to RGB, so it shouldn't happen
@staticmethod | ||
def _interpolation_resolver(resample: Optional[str] = None) -> Image.Resampling: | ||
interpolation_map = { | ||
"nearest": Image.Resampling.NEAREST, | ||
"lanczos": Image.Resampling.LANCZOS, | ||
"bilinear": Image.Resampling.BILINEAR, | ||
"bicubic": Image.Resampling.BICUBIC, | ||
"box": Image.Resampling.BOX, | ||
"hamming": Image.Resampling.HAMMING, | ||
} | ||
|
||
if resample and (method := interpolation_map.get(resample.lower())): | ||
return method | ||
|
||
raise ValueError(f"Unknown interpolation method: {resample}") |
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.
feels like it should not be a part of Compose
class
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 felt the same. Got any suggestions ? fastembed/common/utils ?
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.
idk for sure, we can just move it out of the class
at least, this Compose._interpolation_resolver
is super ugly, if we keep this method here, we need to make get_resize
a class method, not a static, it is only used inside of Compose
class anyway
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've changed get_resize to cls method as _interpolation_resolver would only be used in here
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.
please look at the comments above
new: added resize2square
Co-authored-by: George <[email protected]>
74a381e
to
7627d78
Compare
Adding jinaai/jina-clip-v1
They provided two examples, the first one works and the second one complains about missing
jinaai/jina-clip-v1/sentence_xlnet_config.json
. The output of the first one seems to have small numbers, like they are normallized but its not mentioned so not sure tbh.Update:
The text model needs pooling and normalizing
The image model needs the image to be square
All Submissions:
New Feature Submissions:
pre-commit
withpip3 install pre-commit
and set up hooks withpre-commit install
?New models submission: