haodongli commited on
Commit
5f0675a
1 Parent(s): a47128f

add resizing

Browse files
Files changed (1) hide show
  1. infer.py +8 -0
infer.py CHANGED
@@ -34,6 +34,14 @@ def infer_pipe(pipe, test_image, task_name, seed, device, video_depth=False):
34
  if video_depth == False:
35
  test_image = Image.open(test_image).convert('RGB')
36
  test_image = np.array(test_image).astype(np.float16)
 
 
 
 
 
 
 
 
37
  test_image = torch.tensor(test_image).permute(2,0,1).unsqueeze(0)
38
  test_image = test_image / 127.5 - 1.0
39
  test_image = test_image.to(device)
 
34
  if video_depth == False:
35
  test_image = Image.open(test_image).convert('RGB')
36
  test_image = np.array(test_image).astype(np.float16)
37
+ if max(test_image.shape[:2]) > 1024:
38
+ # resize for a maximum size of 1024
39
+ scale = 1024 / max(test_image.shape[:2])
40
+ test_image = cv2.resize(test_image, (0, 0), fx=scale, fy=scale)
41
+ elif min(test_image.shape[:2]) < 256:
42
+ # resize for a minimum size of 256
43
+ scale = 256 / min(test_image.shape[:2])
44
+ test_image = cv2.resize(test_image, (0, 0), fx=scale, fy=scale)
45
  test_image = torch.tensor(test_image).permute(2,0,1).unsqueeze(0)
46
  test_image = test_image / 127.5 - 1.0
47
  test_image = test_image.to(device)