some debugging
Browse files
app.py
CHANGED
|
@@ -19,14 +19,22 @@ model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
|
| 19 |
|
| 20 |
@app.post('/image')
|
| 21 |
def read_image(image_file: bytes = File(...)):
|
| 22 |
-
|
| 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]])
|
| 29 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return results
|
| 31 |
|
| 32 |
|
|
|
|
| 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 |
+
print("image loaded")
|
| 28 |
outputs = model(**inputs)
|
| 29 |
target_sizes = torch.tensor([image.size[::-1]])
|
| 30 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
| 31 |
+
print("results pushed")
|
| 32 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 33 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 34 |
+
print(
|
| 35 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
| 36 |
+
f"{round(score.item(), 3)} at location {box}"
|
| 37 |
+
)
|
| 38 |
return results
|
| 39 |
|
| 40 |
|