huntrezz commited on
Commit
726a72f
·
verified ·
1 Parent(s): a1f61d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -3,14 +3,19 @@ import torch
3
  import numpy as np
4
  from transformers import DPTForDepthEstimation, DPTImageProcessor
5
  import gradio as gr
 
6
 
7
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
- model = DPTForDepthEstimation.from_pretrained("Intel/dpt-swinv2-tiny-256", torch_dtype=torch.float16).to(device)
 
 
 
 
9
  processor = DPTImageProcessor.from_pretrained("Intel/dpt-swinv2-tiny-256")
10
 
11
  color_map = cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_INFERNO)
12
 
13
- input_tensor = torch.zeros((1, 3, 128, 128), dtype=torch.float16, device=device)
14
  depth_map = np.zeros((128, 128), dtype=np.float32)
15
  depth_map_colored = np.zeros((128, 128, 3), dtype=np.uint8)
16
 
 
3
  import numpy as np
4
  from transformers import DPTForDepthEstimation, DPTImageProcessor
5
  import gradio as gr
6
+ import torch.quantization
7
 
8
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
+ model = DPTForDepthEstimation.from_pretrained("Intel/dpt-swinv2-tiny-256", torch_dtype=torch.float32)
10
+ model.eval()
11
+ model = torch.quantization.quantize_dynamic(
12
+ model, {torch.nn.Linear, torch.nn.Conv2d}, dtype=torch.qint8
13
+ ).to(device)
14
  processor = DPTImageProcessor.from_pretrained("Intel/dpt-swinv2-tiny-256")
15
 
16
  color_map = cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_INFERNO)
17
 
18
+ input_tensor = torch.zeros((1, 3, 128, 128), dtype=torch.float32, device=device)
19
  depth_map = np.zeros((128, 128), dtype=np.float32)
20
  depth_map_colored = np.zeros((128, 128, 3), dtype=np.uint8)
21