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

add resizing

Browse files
Files changed (1) hide show
  1. infer.py +6 -3
infer.py CHANGED
@@ -33,15 +33,18 @@ def infer_pipe(pipe, test_image, task_name, seed, device, video_depth=False):
33
 
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)
 
33
 
34
  if video_depth == False:
35
  test_image = Image.open(test_image).convert('RGB')
36
+ test_image = np.array(test_image).astype(np.float32)
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
  elif min(test_image.shape[:2]) < 256:
41
  # resize for a minimum size of 256
42
  scale = 256 / min(test_image.shape[:2])
43
+ else:
44
+ scale = 1.0
45
+ new_shape = (int(test_image.shape[1] * scale), int(test_image.shape[0] * scale))
46
+ test_image = cv2.resize(test_image, new_shape)
47
+ test_image = test_image.astype(np.float16)
48
  test_image = torch.tensor(test_image).permute(2,0,1).unsqueeze(0)
49
  test_image = test_image / 127.5 - 1.0
50
  test_image = test_image.to(device)