Commit
•
cb05228
1
Parent(s):
ecd409c
Decoding image in input
Browse files- pipeline.py +5 -1
pipeline.py
CHANGED
@@ -2,6 +2,8 @@ from typing import Dict, List, Any
|
|
2 |
from PIL import Image
|
3 |
import requests
|
4 |
import torch
|
|
|
|
|
5 |
from blip import blip_decoder
|
6 |
from torchvision import transforms
|
7 |
from torchvision.transforms.functional import InterpolationMode
|
@@ -36,9 +38,11 @@ class PreTrainedPipeline():
|
|
36 |
- "label": A string representing what the label/class is. There can be multiple labels.
|
37 |
- "score": A score between 0 and 1 describing how confident the model is for this label/class.
|
38 |
"""
|
39 |
-
|
40 |
parameters = data.pop("parameters", None)
|
41 |
|
|
|
|
|
42 |
image = transform(image).unsqueeze(0).to(device)
|
43 |
with torch.no_grad():
|
44 |
caption = self.model.generate(image, sample=True, top_p=0.9, max_length=20, min_length=5)
|
|
|
2 |
from PIL import Image
|
3 |
import requests
|
4 |
import torch
|
5 |
+
import base64
|
6 |
+
from io import BytesIO
|
7 |
from blip import blip_decoder
|
8 |
from torchvision import transforms
|
9 |
from torchvision.transforms.functional import InterpolationMode
|
|
|
38 |
- "label": A string representing what the label/class is. There can be multiple labels.
|
39 |
- "score": A score between 0 and 1 describing how confident the model is for this label/class.
|
40 |
"""
|
41 |
+
inputs = data.pop("inputs", data)
|
42 |
parameters = data.pop("parameters", None)
|
43 |
|
44 |
+
# decode base64 image to PIL
|
45 |
+
image = Image.open(BytesIO(base64.b64decode(inputs['image'])))
|
46 |
image = transform(image).unsqueeze(0).to(device)
|
47 |
with torch.no_grad():
|
48 |
caption = self.model.generate(image, sample=True, top_p=0.9, max_length=20, min_length=5)
|