Spaces:
Runtime error
Runtime error
fix load image
Browse files
app.py
CHANGED
|
@@ -41,22 +41,18 @@ texts = st.text_input('apple, eggs')
|
|
| 41 |
image = ''
|
| 42 |
if uploaded_image_zero_file is not None:
|
| 43 |
with NamedTemporaryFile() as temp:
|
| 44 |
-
temp.write(uploaded_image_zero_file.getvalue())
|
| 45 |
-
temp.seek(0)
|
| 46 |
image = Image.open(uploaded_image_zero_file)
|
| 47 |
outputImage = np.array(image)
|
| 48 |
st.image(outputImage)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
box = [round(i, 2) for i in box.tolist()]
|
| 62 |
-
print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
|
|
|
|
| 41 |
image = ''
|
| 42 |
if uploaded_image_zero_file is not None:
|
| 43 |
with NamedTemporaryFile() as temp:
|
|
|
|
|
|
|
| 44 |
image = Image.open(uploaded_image_zero_file)
|
| 45 |
outputImage = np.array(image)
|
| 46 |
st.image(outputImage)
|
| 47 |
+
inputs = processor(text=texts, images=image, return_tensors="pt")
|
| 48 |
+
outputs = model(**inputs)
|
| 49 |
+
target_sizes = torch.Tensor([image.size[::-1]])
|
| 50 |
+
results = processor.post_process_object_detection(outputs=outputs, threshold=0.1, target_sizes=target_sizes)
|
| 51 |
+
i = 0 # Retrieve predictions for the first image for the corresponding text queries
|
| 52 |
+
text = texts[i]
|
| 53 |
+
boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
|
| 54 |
+
st.write(results)
|
| 55 |
+
# Print detected objects and rescaled box coordinates
|
| 56 |
+
for box, score, label in zip(boxes, scores, labels):
|
| 57 |
+
box = [round(i, 2) for i in box.tolist()]
|
| 58 |
+
print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
|
|
|
|
|
|