baconseason commited on
Commit
42ff6ec
·
1 Parent(s): 4a2ff96
Files changed (1) hide show
  1. handler.py +6 -1
handler.py CHANGED
@@ -5,13 +5,16 @@ import requests
5
  import numpy as np
6
  from cv2 import imencode
7
  from base64 import b64encode
 
8
 
9
  class EndpointHandler():
10
  def __init__(self, path=""):
11
  self.device = "cuda" if torch.cuda.is_available() else "cpu"
 
12
  self.generator = pipeline("mask-generation", model="facebook/sam-vit-large", device=self.device)
13
 
14
  def __call__(self, data):
 
15
  inputs = data.pop("inputs", data)
16
  raw_image = Image.open(requests.get(inputs, stream=True).raw).convert("RGB")
17
 
@@ -31,5 +34,7 @@ class EndpointHandler():
31
  "mask": encoded_mask,
32
  "label": ""
33
  })
 
 
34
 
35
- return data
 
5
  import numpy as np
6
  from cv2 import imencode
7
  from base64 import b64encode
8
+ import time
9
 
10
  class EndpointHandler():
11
  def __init__(self, path=""):
12
  self.device = "cuda" if torch.cuda.is_available() else "cpu"
13
+ print(f"Using device: {self.device}")
14
  self.generator = pipeline("mask-generation", model="facebook/sam-vit-large", device=self.device)
15
 
16
  def __call__(self, data):
17
+ start = time.time()
18
  inputs = data.pop("inputs", data)
19
  raw_image = Image.open(requests.get(inputs, stream=True).raw).convert("RGB")
20
 
 
34
  "mask": encoded_mask,
35
  "label": ""
36
  })
37
+
38
+ end = time.time()
39
 
40
+ return { "data": data, "time": end - start }