sachin commited on
Commit
36d8d67
1 Parent(s): 308043b

Aspect ratio bug

Browse files

Apologies if I haven't understood how resizing works with PIL. With this the following bit of the (original) code, it seems you set `aspect_ratio = width / height`, but when comparing, you swap the two. Reason I have swapped the two is because in the first line you have `width, height = image.size`
```python
width, height = image.size
max_dim = max(width, height)
if max_dim < 512:
im_size = (378, 378)
else:
aspect_ratio = width / height
im_size = min(
self.supported_sizes,
key=lambda size: (
abs((size[1] / size[0]) - aspect_ratio),
abs(size[0] - width) + abs(size[1] - height),
),
)
```

Files changed (1) hide show
  1. vision_encoder.py +1 -1
vision_encoder.py CHANGED
@@ -233,7 +233,7 @@ class VisionEncoder(nn.Module):
233
  im_size = min(
234
  self.supported_sizes,
235
  key=lambda size: (
236
- abs((size[1] / size[0]) - aspect_ratio),
237
  abs(size[0] - width) + abs(size[1] - height),
238
  ),
239
  )
 
233
  im_size = min(
234
  self.supported_sizes,
235
  key=lambda size: (
236
+ abs((size[0] / size[1]) - aspect_ratio),
237
  abs(size[0] - width) + abs(size[1] - height),
238
  ),
239
  )