Spaces:
Sleeping
Sleeping
Updated object detection
Browse files
app.py
CHANGED
@@ -53,11 +53,11 @@ def initialise_object_detection_model():
|
|
53 |
return detector
|
54 |
|
55 |
# Function to get result from object detection
|
56 |
-
def get_object_detection_results(detector, image_path):
|
57 |
image = Image.open(image_path)
|
58 |
predictions = detector(
|
59 |
image,
|
60 |
-
candidate_labels=
|
61 |
)
|
62 |
draw = ImageDraw.Draw(image)
|
63 |
for prediction in predictions:
|
@@ -208,7 +208,8 @@ if st.session_state['authentication_status']:
|
|
208 |
st.write('\n')
|
209 |
st.write('\n')
|
210 |
st.write("Try OWL-ViT:")
|
211 |
-
object_labels = st.
|
|
|
212 |
image_file = st.file_uploader("Upload an image", type=["jpg", "png"])
|
213 |
demo_image = st.checkbox("Load in demo image")
|
214 |
if image_file:
|
@@ -217,14 +218,14 @@ if st.session_state['authentication_status']:
|
|
217 |
if image_file and object_labels:
|
218 |
st.write('After:')
|
219 |
with st.spinner("Detecting"):
|
220 |
-
st.image(image = get_object_detection_results(detector, image_file))
|
221 |
if demo_image:
|
222 |
st.write('Before:')
|
223 |
st.image("images/fly.jpg")
|
224 |
if demo_image and object_labels:
|
225 |
st.write('After:')
|
226 |
with st.spinner("Detecting"):
|
227 |
-
st.image(image = get_object_detection_results(detector, "images/fly.jpg"))
|
228 |
st.write('\n')
|
229 |
st.write('\n')
|
230 |
st.write("2) Behaviour Analysis - By comparing consecutive frames, the system can extract data such as the trajectory, speed, and direction of each fly's movement. Training the system on these data can improve the system's detection of flies.")
|
|
|
53 |
return detector
|
54 |
|
55 |
# Function to get result from object detection
|
56 |
+
def get_object_detection_results(detector, image_path, object_labels):
|
57 |
image = Image.open(image_path)
|
58 |
predictions = detector(
|
59 |
image,
|
60 |
+
candidate_labels=object_labels,
|
61 |
)
|
62 |
draw = ImageDraw.Draw(image)
|
63 |
for prediction in predictions:
|
|
|
208 |
st.write('\n')
|
209 |
st.write('\n')
|
210 |
st.write("Try OWL-ViT:")
|
211 |
+
object_labels = st.text_input("Enter your labels for the model to detect (comma-separated)", value="insect")
|
212 |
+
labels = object_labels.split(", ")
|
213 |
image_file = st.file_uploader("Upload an image", type=["jpg", "png"])
|
214 |
demo_image = st.checkbox("Load in demo image")
|
215 |
if image_file:
|
|
|
218 |
if image_file and object_labels:
|
219 |
st.write('After:')
|
220 |
with st.spinner("Detecting"):
|
221 |
+
st.image(image = get_object_detection_results(detector, image_file, labels))
|
222 |
if demo_image:
|
223 |
st.write('Before:')
|
224 |
st.image("images/fly.jpg")
|
225 |
if demo_image and object_labels:
|
226 |
st.write('After:')
|
227 |
with st.spinner("Detecting"):
|
228 |
+
st.image(image = get_object_detection_results(detector, "images/fly.jpg", labels))
|
229 |
st.write('\n')
|
230 |
st.write('\n')
|
231 |
st.write("2) Behaviour Analysis - By comparing consecutive frames, the system can extract data such as the trajectory, speed, and direction of each fly's movement. Training the system on these data can improve the system's detection of flies.")
|