Commit
·
2d7803c
1
Parent(s):
e1a8581
logging
Browse files- handler.py +6 -2
handler.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import torch
|
2 |
from transformers import pipeline
|
|
|
3 |
from PIL import Image
|
4 |
import requests
|
5 |
import numpy as np
|
@@ -7,16 +8,19 @@ 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 |
-
|
|
|
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 |
-
|
20 |
raw_image = Image.open(requests.get(inputs, stream=True).raw).convert("RGB")
|
21 |
|
22 |
with torch.no_grad():
|
|
|
1 |
import torch
|
2 |
from transformers import pipeline
|
3 |
+
from transformers.utils import logging
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
import numpy as np
|
|
|
8 |
from base64 import b64encode
|
9 |
import time
|
10 |
|
11 |
+
logging.set_verbosity_info()
|
12 |
+
|
13 |
class EndpointHandler():
|
14 |
def __init__(self, path=""):
|
15 |
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
+
self.logger = logging.get_logger("transformers")
|
17 |
+
self.logger.info(f"Using device: {self.device}")
|
18 |
self.generator = pipeline("mask-generation", model="facebook/sam-vit-large", device=self.device)
|
19 |
|
20 |
def __call__(self, data):
|
21 |
start = time.time()
|
22 |
inputs = data.pop("inputs", data)
|
23 |
+
self.logger.info(f"got request for {inputs}")
|
24 |
raw_image = Image.open(requests.get(inputs, stream=True).raw).convert("RGB")
|
25 |
|
26 |
with torch.no_grad():
|