image from url
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
|
|
5 |
from io import BytesIO
|
6 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
7 |
import torch
|
8 |
-
|
9 |
|
10 |
app = FastAPI(title="Object Detection",
|
11 |
docs_url="/",
|
@@ -19,7 +19,10 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
|
19 |
|
20 |
@app.post('/image')
|
21 |
def read_image(image_file: bytes = File(...)):
|
22 |
-
image = Image.open(BytesIO(image_file))
|
|
|
|
|
|
|
23 |
inputs = processor(images=image, return_tensors="pt")
|
24 |
outputs = model(**inputs)
|
25 |
target_sizes = torch.tensor([image.size[::-1]])
|
|
|
5 |
from io import BytesIO
|
6 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
7 |
import torch
|
8 |
+
import requests
|
9 |
|
10 |
app = FastAPI(title="Object Detection",
|
11 |
docs_url="/",
|
|
|
19 |
|
20 |
@app.post('/image')
|
21 |
def read_image(image_file: bytes = File(...)):
|
22 |
+
#image = Image.open(BytesIO(image_file))
|
23 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
24 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
25 |
+
|
26 |
inputs = processor(images=image, return_tensors="pt")
|
27 |
outputs = model(**inputs)
|
28 |
target_sizes = torch.tensor([image.size[::-1]])
|