haodongli commited on
Commit
4d23710
1 Parent(s): 3e42be9

add resizing

Browse files
Files changed (1) hide show
  1. infer.py +12 -1
infer.py CHANGED
@@ -32,7 +32,18 @@ def infer_pipe(pipe, image_input, task_name, seed, device):
32
  with autocast_ctx:
33
 
34
  test_image = Image.open(image_input).convert('RGB')
35
- test_image = np.array(test_image).astype(np.float16)
 
 
 
 
 
 
 
 
 
 
 
36
  test_image = torch.tensor(test_image).permute(2,0,1).unsqueeze(0)
37
  test_image = test_image / 127.5 - 1.0
38
  test_image = test_image.to(device)
 
32
  with autocast_ctx:
33
 
34
  test_image = Image.open(image_input).convert('RGB')
35
+ test_image = np.array(test_image).astype(np.float32)
36
+ if max(test_image.shape[:2]) > 1024:
37
+ # resize for a maximum size of 1024
38
+ scale = 1024 / max(test_image.shape[:2])
39
+ elif min(test_image.shape[:2]) < 384:
40
+ # resize for a minimum size of 384
41
+ scale = 384 / min(test_image.shape[:2])
42
+ else:
43
+ scale = 1.0
44
+ new_shape = (int(test_image.shape[1] * scale), int(test_image.shape[0] * scale))
45
+ test_image = cv2.resize(test_image, new_shape)
46
+ test_image = test_image.astype(np.float16)
47
  test_image = torch.tensor(test_image).permute(2,0,1).unsqueeze(0)
48
  test_image = test_image / 127.5 - 1.0
49
  test_image = test_image.to(device)