Spaces:
Runtime error
Runtime error
trying zero object detection
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from transformers import pipeline, OwlViTProcessor, OwlViTForObjectDetection
|
| 5 |
from tempfile import NamedTemporaryFile
|
|
@@ -40,8 +42,10 @@ if uploaded_image_zero_file is not None:
|
|
| 40 |
with NamedTemporaryFile() as temp:
|
| 41 |
temp.write(uploaded_image_zero_file.getvalue())
|
| 42 |
temp.seek(0)
|
|
|
|
|
|
|
|
|
|
| 43 |
image = Image.open(temp.name)
|
| 44 |
-
st.image(image)
|
| 45 |
inputs = processor(text=texts, images=image, return_tensors="pt")
|
| 46 |
outputs = model(**inputs)
|
| 47 |
target_sizes = torch.Tensor([image.size[::-1]])
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
from transformers import pipeline, OwlViTProcessor, OwlViTForObjectDetection
|
| 7 |
from tempfile import NamedTemporaryFile
|
|
|
|
| 42 |
with NamedTemporaryFile() as temp:
|
| 43 |
temp.write(uploaded_image_zero_file.getvalue())
|
| 44 |
temp.seek(0)
|
| 45 |
+
file_bytes = np.asarray(bytearray(uploaded_image_zero_file.read()), dtype=np.uint8)
|
| 46 |
+
opencv_image = cv2.imdecode(file_bytes, 1)
|
| 47 |
+
st.image(opencv_image, channels="BGR")
|
| 48 |
image = Image.open(temp.name)
|
|
|
|
| 49 |
inputs = processor(text=texts, images=image, return_tensors="pt")
|
| 50 |
outputs = model(**inputs)
|
| 51 |
target_sizes = torch.Tensor([image.size[::-1]])
|