-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (22 loc) · 912 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from transformers import DetrFeatureExtractor, DetrForObjectDetection
from PIL import Image
import streamlit as st
import numpy as np
import requests
def image_read(url_image):
# url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(url_image)
feature_extractor = DetrFeatureExtractor.from_pretrained('facebook/detr-resnet-50')
model = DetrForObjectDetection.from_pretrained('facebook/detr-resnet-50')
inputs = feature_extractor(images=image, return_tensors="pt")
outputs = model(**inputs)
# model predicts bounding boxes and corresponding COCO classes
logits = outputs.logits
bboxes = outputs.pred_boxes
return logits, bboxes
if __name__ == '__main__':
url_image = "./images/image.jpg"
bboxes,logits = image_read(url_image)
# print(logits, bboxes)
st.image(url_image, use_column_width=True)
st.write(bboxes)