umuthopeyildirim commited on
Commit
0f1bbf6
1 Parent(s): 8b0757c

Add matplotlib.pyplot import and modify depth visualization code

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -9,6 +9,7 @@ import torch.nn.functional as F
9
  from torchvision.transforms import Compose, Normalize
10
  import tempfile
11
  from gradio_imageslider import ImageSlider
 
12
 
13
  from iebins.networks.NewCRFDepth import NewCRFDepth
14
  from iebins.util.transfrom import Resize, NormalizeImage, PrepareForNet
@@ -94,22 +95,18 @@ with gr.Blocks(css=css) as demo:
94
  # image = torch.from_numpy(image).unsqueeze(0)
95
  image = torch.autograd.Variable(image.unsqueeze(0))
96
 
97
- pred_depths_r_list, _, _ = predict_depth(model, image)
98
  image_flipped = flip_lr(image)
99
  pred_depths_r_list_flipped, _, _ = model(image_flipped)
100
  pred_depth = post_process_depth(
101
  pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
102
 
103
  pred_depth = pred_depth.cpu().numpy().squeeze()
 
 
104
 
105
- raw_depth = Image.fromarray(pred_depth.cpu().numpy().astype('uint16'))
106
  tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
107
- raw_depth.save(tmp.name)
108
-
109
- depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
110
- depth = depth.cpu().numpy().astype(np.uint8)
111
- colored_depth = cv2.applyColorMap(
112
- depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]
113
 
114
  return [(original_image, colored_depth), tmp.name]
115
 
 
9
  from torchvision.transforms import Compose, Normalize
10
  import tempfile
11
  from gradio_imageslider import ImageSlider
12
+ import matplotlib.pyplot as plt
13
 
14
  from iebins.networks.NewCRFDepth import NewCRFDepth
15
  from iebins.util.transfrom import Resize, NormalizeImage, PrepareForNet
 
95
  # image = torch.from_numpy(image).unsqueeze(0)
96
  image = torch.autograd.Variable(image.unsqueeze(0))
97
 
98
+ pred_depths_r_list, _, _ = model(image)
99
  image_flipped = flip_lr(image)
100
  pred_depths_r_list_flipped, _, _ = model(image_flipped)
101
  pred_depth = post_process_depth(
102
  pred_depths_r_list[-1], pred_depths_r_list_flipped[-1])
103
 
104
  pred_depth = pred_depth.cpu().numpy().squeeze()
105
+ colored_depth = cv2.applyColorMap(
106
+ pred_depth, cv2.COLORMAP_INFERNO)[:, :, ::-1]
107
 
 
108
  tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
109
+ pred_depth.save(tmp.name)
 
 
 
 
 
110
 
111
  return [(original_image, colored_depth), tmp.name]
112