Spaces:
Runtime error
Runtime error
IoU evaluator
Browse files- .idea/workspace.xml +33 -30
- demo.py +63 -19
- yolo_dataset.py +10 -4
.idea/workspace.xml
CHANGED
|
@@ -4,16 +4,10 @@
|
|
| 4 |
<option name="autoReloadType" value="SELECTIVE" />
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
-
<list default="true" id="d7806539-b6d6-42e7-bb45-1565f5d54891" name="Changes" comment="
|
| 8 |
-
<change afterPath="$PROJECT_DIR$/evaluator.py" afterDir="false" />
|
| 9 |
-
<change afterPath="$PROJECT_DIR$/tests/coco8.zip" afterDir="false" />
|
| 10 |
-
<change afterPath="$PROJECT_DIR$/tests/project-2-at-2024-01-20-11-43-00ad4911.zip" afterDir="false" />
|
| 11 |
-
<change afterPath="$PROJECT_DIR$/yolo_dataset.py" afterDir="false" />
|
| 12 |
-
<change beforePath="$PROJECT_DIR$/.idea/detector.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/detector.iml" afterDir="false" />
|
| 13 |
-
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
| 14 |
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
| 15 |
<change beforePath="$PROJECT_DIR$/demo.py" beforeDir="false" afterPath="$PROJECT_DIR$/demo.py" afterDir="false" />
|
| 16 |
-
<change beforePath="$PROJECT_DIR$/
|
| 17 |
</list>
|
| 18 |
<option name="SHOW_DIALOG" value="false" />
|
| 19 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -47,25 +41,25 @@
|
|
| 47 |
<option name="hideEmptyMiddlePackages" value="true" />
|
| 48 |
<option name="showLibraryContents" value="true" />
|
| 49 |
</component>
|
| 50 |
-
<component name="PropertiesComponent"
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
}
|
| 68 |
-
}
|
| 69 |
<component name="RecentsManager">
|
| 70 |
<key name="CopyFile.RECENT_KEYS">
|
| 71 |
<recent name="$PROJECT_DIR$/tests" />
|
|
@@ -187,7 +181,7 @@
|
|
| 187 |
<workItem from="1702301554378" duration="4025000" />
|
| 188 |
<workItem from="1702450051021" duration="10065000" />
|
| 189 |
<workItem from="1702476484538" duration="9613000" />
|
| 190 |
-
<workItem from="1705757850315" duration="
|
| 191 |
</task>
|
| 192 |
<task id="LOCAL-00001" summary="init commit">
|
| 193 |
<option name="closed" value="true" />
|
|
@@ -325,7 +319,15 @@
|
|
| 325 |
<option name="project" value="LOCAL" />
|
| 326 |
<updated>1702485964999</updated>
|
| 327 |
</task>
|
| 328 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
<servers />
|
| 330 |
</component>
|
| 331 |
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -367,11 +369,12 @@
|
|
| 367 |
<MESSAGE value="use env" />
|
| 368 |
<MESSAGE value="use /run/secrets" />
|
| 369 |
<MESSAGE value="fix confidence" />
|
| 370 |
-
<
|
|
|
|
| 371 |
</component>
|
| 372 |
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
| 373 |
<SUITE FILE_PATH="coverage/detector$demo.coverage" NAME="demo Coverage Results" MODIFIED="1702302380580" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 374 |
-
<SUITE FILE_PATH="coverage/detector$evaluator.coverage" NAME="evaluator Coverage Results" MODIFIED="
|
| 375 |
<SUITE FILE_PATH="coverage/detector$extract.coverage" NAME="yolo_dataset Coverage Results" MODIFIED="1705764465837" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 376 |
</component>
|
| 377 |
</project>
|
|
|
|
| 4 |
<option name="autoReloadType" value="SELECTIVE" />
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
+
<list default="true" id="d7806539-b6d6-42e7-bb45-1565f5d54891" name="Changes" comment="IoU evaluator">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
| 9 |
<change beforePath="$PROJECT_DIR$/demo.py" beforeDir="false" afterPath="$PROJECT_DIR$/demo.py" afterDir="false" />
|
| 10 |
+
<change beforePath="$PROJECT_DIR$/yolo_dataset.py" beforeDir="false" afterPath="$PROJECT_DIR$/yolo_dataset.py" afterDir="false" />
|
| 11 |
</list>
|
| 12 |
<option name="SHOW_DIALOG" value="false" />
|
| 13 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
|
|
| 41 |
<option name="hideEmptyMiddlePackages" value="true" />
|
| 42 |
<option name="showLibraryContents" value="true" />
|
| 43 |
</component>
|
| 44 |
+
<component name="PropertiesComponent">{
|
| 45 |
+
"keyToString": {
|
| 46 |
+
"Python.demo.executor": "Run",
|
| 47 |
+
"Python.evaluator.executor": "Debug",
|
| 48 |
+
"Python.extract.executor": "Run",
|
| 49 |
+
"Python.yolo_dataset.executor": "Run",
|
| 50 |
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
| 51 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
| 52 |
+
"git-widget-placeholder": "main",
|
| 53 |
+
"last_opened_file_path": "/Users/famer.me/PycharmProjects/detector/tests",
|
| 54 |
+
"node.js.detected.package.eslint": "true",
|
| 55 |
+
"node.js.detected.package.tslint": "true",
|
| 56 |
+
"node.js.selected.package.eslint": "(autodetect)",
|
| 57 |
+
"node.js.selected.package.tslint": "(autodetect)",
|
| 58 |
+
"nodejs_package_manager_path": "npm",
|
| 59 |
+
"settings.editor.selected.configurable": "settings.qodana",
|
| 60 |
+
"vue.rearranger.settings.migration": "true"
|
| 61 |
}
|
| 62 |
+
}</component>
|
| 63 |
<component name="RecentsManager">
|
| 64 |
<key name="CopyFile.RECENT_KEYS">
|
| 65 |
<recent name="$PROJECT_DIR$/tests" />
|
|
|
|
| 181 |
<workItem from="1702301554378" duration="4025000" />
|
| 182 |
<workItem from="1702450051021" duration="10065000" />
|
| 183 |
<workItem from="1702476484538" duration="9613000" />
|
| 184 |
+
<workItem from="1705757850315" duration="12403000" />
|
| 185 |
</task>
|
| 186 |
<task id="LOCAL-00001" summary="init commit">
|
| 187 |
<option name="closed" value="true" />
|
|
|
|
| 319 |
<option name="project" value="LOCAL" />
|
| 320 |
<updated>1702485964999</updated>
|
| 321 |
</task>
|
| 322 |
+
<task id="LOCAL-00018" summary="IoU evaluator">
|
| 323 |
+
<option name="closed" value="true" />
|
| 324 |
+
<created>1705768358117</created>
|
| 325 |
+
<option name="number" value="00018" />
|
| 326 |
+
<option name="presentableId" value="LOCAL-00018" />
|
| 327 |
+
<option name="project" value="LOCAL" />
|
| 328 |
+
<updated>1705768358117</updated>
|
| 329 |
+
</task>
|
| 330 |
+
<option name="localTasksCounter" value="19" />
|
| 331 |
<servers />
|
| 332 |
</component>
|
| 333 |
<component name="TypeScriptGeneratedFilesManager">
|
|
|
|
| 369 |
<MESSAGE value="use env" />
|
| 370 |
<MESSAGE value="use /run/secrets" />
|
| 371 |
<MESSAGE value="fix confidence" />
|
| 372 |
+
<MESSAGE value="IoU evaluator" />
|
| 373 |
+
<option name="LAST_COMMIT_MESSAGE" value="IoU evaluator" />
|
| 374 |
</component>
|
| 375 |
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
| 376 |
<SUITE FILE_PATH="coverage/detector$demo.coverage" NAME="demo Coverage Results" MODIFIED="1702302380580" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 377 |
+
<SUITE FILE_PATH="coverage/detector$evaluator.coverage" NAME="evaluator Coverage Results" MODIFIED="1705768332357" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 378 |
<SUITE FILE_PATH="coverage/detector$extract.coverage" NAME="yolo_dataset Coverage Results" MODIFIED="1705764465837" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
| 379 |
</component>
|
| 380 |
</project>
|
demo.py
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
|
|
| 1 |
import time
|
| 2 |
-
from
|
|
|
|
|
|
|
|
|
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
|
|
|
|
|
|
|
| 5 |
from yolo_fire import detect
|
| 6 |
|
| 7 |
|
|
@@ -12,28 +19,65 @@ def main():
|
|
| 12 |
layout="centered")
|
| 13 |
st.title("Fire&Smoke Detection:")
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
if buffer:
|
| 19 |
-
# Object Detecting
|
| 20 |
-
with st.spinner('Wait for it...'):
|
| 21 |
-
# Slider for changing confidence
|
| 22 |
-
confidence = st.slider('Confidence Threshold', 0, 100, 30)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
im = Image.open(buffer)
|
| 27 |
-
# im.save("saved_images/image.jpg")
|
| 28 |
-
res_img = detect(im, confidence / 100.0)
|
| 29 |
-
t2 = time.time()
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
st.write("\n")
|
| 36 |
-
st.write("Time taken: ", t2 - t1, "sec.")
|
| 37 |
|
| 38 |
|
| 39 |
if __name__ == '__main__':
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
import time
|
| 3 |
+
from functools import wraps
|
| 4 |
+
from io import StringIO
|
| 5 |
+
from zipfile import ZipFile
|
| 6 |
+
|
| 7 |
import streamlit as st
|
| 8 |
+
from PIL import Image
|
| 9 |
|
| 10 |
+
import evaluator
|
| 11 |
+
from yolo_dataset import YoloDataset
|
| 12 |
from yolo_fire import detect
|
| 13 |
|
| 14 |
|
|
|
|
| 19 |
layout="centered")
|
| 20 |
st.title("Fire&Smoke Detection:")
|
| 21 |
|
| 22 |
+
detect_tab, evaluate_tab = st.tabs(["Detect", "Evaluate"])
|
| 23 |
+
|
| 24 |
+
with evaluate_tab:
|
| 25 |
+
buffer = st.file_uploader("Upload your Yolo Dataset here", type=["zip"])
|
| 26 |
+
|
| 27 |
+
if buffer:
|
| 28 |
+
with st.spinner('Wait for it...'):
|
| 29 |
+
# Slider for changing confidence
|
| 30 |
+
confidence = st.slider('Confidence Threshold', 0, 100, 30)
|
| 31 |
+
yolo_dataset = YoloDataset.from_zip_file(ZipFile(buffer))
|
| 32 |
+
capture_output(evaluator.evaluate)(coco_gt=yolo_dataset.to_coco(), loader=yolo_dataset.load_image,
|
| 33 |
+
confidence_threshold=confidence / 100.0)
|
| 34 |
+
|
| 35 |
+
with detect_tab:
|
| 36 |
+
# This will let you upload PNG, JPG & JPEG File
|
| 37 |
+
buffer = st.file_uploader("Upload your Image here", type=["jpg", "png", "jpeg"])
|
| 38 |
+
|
| 39 |
+
if buffer:
|
| 40 |
+
# Object Detecting
|
| 41 |
+
with st.spinner('Wait for it...'):
|
| 42 |
+
# Slider for changing confidence
|
| 43 |
+
confidence = st.slider('Confidence Threshold', 0, 100, 30)
|
| 44 |
+
|
| 45 |
+
# Calculating time for detection
|
| 46 |
+
t1 = time.time()
|
| 47 |
+
im = Image.open(buffer)
|
| 48 |
+
# im.save("saved_images/image.jpg")
|
| 49 |
+
res_img = detect(im, confidence / 100.0)
|
| 50 |
+
t2 = time.time()
|
| 51 |
+
|
| 52 |
+
# Displaying the image
|
| 53 |
+
st.image(res_img, use_column_width=True)
|
| 54 |
+
|
| 55 |
+
# Printing Time
|
| 56 |
+
st.write("\n")
|
| 57 |
+
st.write("Time taken: ", t2 - t1, "sec.")
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
def capture_output(func):
|
| 61 |
+
"""Capture output from running a function and write using streamlit."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
@wraps(func)
|
| 64 |
+
def wrapper(*args, **kwargs):
|
| 65 |
+
# Redirect output to string buffers
|
| 66 |
+
stdout, stderr = StringIO(), StringIO()
|
| 67 |
+
try:
|
| 68 |
+
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
|
| 69 |
+
return func(*args, **kwargs)
|
| 70 |
+
except Exception as err:
|
| 71 |
+
st.write(f"Failure while executing: {err}")
|
| 72 |
+
finally:
|
| 73 |
+
if _stdout := stdout.getvalue():
|
| 74 |
+
st.write("Execution stdout:")
|
| 75 |
+
st.code(_stdout)
|
| 76 |
+
if _stderr := stderr.getvalue():
|
| 77 |
+
st.write("Execution stderr:")
|
| 78 |
+
st.code(_stderr)
|
| 79 |
|
| 80 |
+
return wrapper
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
if __name__ == '__main__':
|
yolo_dataset.py
CHANGED
|
@@ -12,11 +12,10 @@
|
|
| 12 |
# βββ 1.txt
|
| 13 |
# βββ 2.txt
|
| 14 |
# βββ ...
|
| 15 |
-
import io
|
| 16 |
-
import json
|
| 17 |
from datetime import datetime
|
| 18 |
from typing import Optional
|
| 19 |
from zipfile import ZipFile
|
|
|
|
| 20 |
from PIL import Image
|
| 21 |
from pycocotools import coco
|
| 22 |
from pycocotools.coco import COCO
|
|
@@ -120,8 +119,7 @@ class YoloDataset:
|
|
| 120 |
self._labels = labels
|
| 121 |
|
| 122 |
@staticmethod
|
| 123 |
-
def from_zip_file(zip_file:
|
| 124 |
-
zip_file = ZipFile(zip_file, 'r')
|
| 125 |
namelist = zip_file.namelist()
|
| 126 |
root_name = namelist[0]
|
| 127 |
namelist = list(filter(lambda x: not zip_file.getinfo(x).is_dir(), namelist))
|
|
@@ -140,6 +138,11 @@ class YoloDataset:
|
|
| 140 |
assert image_name.split('.')[0] == label_name.split('.')[0]
|
| 141 |
return YoloDataset(zip_file, classes, images, labels)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
def __len__(self):
|
| 144 |
return len(self._images)
|
| 145 |
|
|
@@ -163,6 +166,9 @@ class YoloDataset:
|
|
| 163 |
for i in range(len(self)):
|
| 164 |
yield self[i]
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
def load_image(self, image_name: str) -> Image:
|
| 167 |
return Image.open(self._zip_file.open(image_name))
|
| 168 |
|
|
|
|
| 12 |
# βββ 1.txt
|
| 13 |
# βββ 2.txt
|
| 14 |
# βββ ...
|
|
|
|
|
|
|
| 15 |
from datetime import datetime
|
| 16 |
from typing import Optional
|
| 17 |
from zipfile import ZipFile
|
| 18 |
+
|
| 19 |
from PIL import Image
|
| 20 |
from pycocotools import coco
|
| 21 |
from pycocotools.coco import COCO
|
|
|
|
| 119 |
self._labels = labels
|
| 120 |
|
| 121 |
@staticmethod
|
| 122 |
+
def from_zip_file(zip_file: ZipFile) -> 'YoloDataset':
|
|
|
|
| 123 |
namelist = zip_file.namelist()
|
| 124 |
root_name = namelist[0]
|
| 125 |
namelist = list(filter(lambda x: not zip_file.getinfo(x).is_dir(), namelist))
|
|
|
|
| 138 |
assert image_name.split('.')[0] == label_name.split('.')[0]
|
| 139 |
return YoloDataset(zip_file, classes, images, labels)
|
| 140 |
|
| 141 |
+
@staticmethod
|
| 142 |
+
def from_path(path: str) -> 'YoloDataset':
|
| 143 |
+
zip_file = ZipFile(path, 'r')
|
| 144 |
+
return YoloDataset.from_zip_file(zip_file)
|
| 145 |
+
|
| 146 |
def __len__(self):
|
| 147 |
return len(self._images)
|
| 148 |
|
|
|
|
| 166 |
for i in range(len(self)):
|
| 167 |
yield self[i]
|
| 168 |
|
| 169 |
+
def __deepcopy__(self, memodict=None):
|
| 170 |
+
return YoloDataset(self._zip_file, self._classes, self._images, self._labels)
|
| 171 |
+
|
| 172 |
def load_image(self, image_name: str) -> Image:
|
| 173 |
return Image.open(self._zip_file.open(image_name))
|
| 174 |
|