|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from transformers import DetrFeatureExtractor, DetrForObjectDetection |
|
from PIL import Image |
|
import requests |
|
|
|
|
|
url = 'http://images.cocodataset.org/val2017/000000039769.jpg' |
|
|
|
|
|
st.write(url) |
|
|
|
image = Image.open(requests.get(url, stream=True).raw) |
|
|
|
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) |
|
|
|
|
|
logits = outputs.logits |
|
bboxes = outputs.pred_boxes |
|
|
|
if bboxes: |
|
st.json(bboxes) |