huy-ha commited on
Commit
9eae628
1 Parent(s): 58c2805

account for aspect ratio

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -42,7 +42,11 @@ def generate_relevancy(
42
  if len(labels) > 32:
43
  labels = labels[:32]
44
  prompts = [prompt]
45
- img = np.asarray(Image.fromarray(img).resize((244 * 4, 244 * 4)))
 
 
 
 
46
  assert img.dtype == np.uint8
47
  h, w, c = img.shape
48
  start = time()
@@ -95,7 +99,7 @@ This relevancy extractor builds heavily on [Chefer et al.'s codebase](https://gi
95
  gr.Image(type="numpy", label="Image"),
96
  gr.Textbox(label="Labels (comma separated without spaces in between)"),
97
  gr.Textbox(
98
- label="Prompt. (Make sure to include \{\} in the prompt like examples below)"
99
  ),
100
  gr.Dropdown(
101
  value="ours",
 
42
  if len(labels) > 32:
43
  labels = labels[:32]
44
  prompts = [prompt]
45
+ resize_shape = np.array(img.shape[:2])
46
+ resize_shape = tuple(
47
+ ((resize_shape / resize_shape.max()) * 224 * 4).astype(int).tolist()
48
+ )
49
+ img = np.asarray(Image.fromarray(img).resize(resize_shape))
50
  assert img.dtype == np.uint8
51
  h, w, c = img.shape
52
  start = time()
 
99
  gr.Image(type="numpy", label="Image"),
100
  gr.Textbox(label="Labels (comma separated without spaces in between)"),
101
  gr.Textbox(
102
+ label="Prompt. (Make sure to include '{}' in the prompt like examples below)"
103
  ),
104
  gr.Dropdown(
105
  value="ours",