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