Spaces:
Runtime error
Runtime error
mingyang91
commited on
fix runtime error in coco evaluator
Browse files- .idea/workspace.xml +37 -30
- demo.py +4 -4
- evaluator.py +10 -14
- yolo_dataset.py +8 -3
.idea/workspace.xml
CHANGED
@@ -4,9 +4,11 @@
|
|
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 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 |
</list>
|
11 |
<option name="SHOW_DIALOG" value="false" />
|
12 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
@@ -55,26 +57,26 @@
|
|
55 |
<option name="hideEmptyMiddlePackages" value="true" />
|
56 |
<option name="showLibraryContents" value="true" />
|
57 |
</component>
|
58 |
-
<component name="PropertiesComponent"
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
}
|
77 |
-
}
|
78 |
<component name="RecentsManager">
|
79 |
<key name="CopyFile.RECENT_KEYS">
|
80 |
<recent name="$PROJECT_DIR$/tests" />
|
@@ -236,7 +238,8 @@
|
|
236 |
<workItem from="1706151430872" duration="1470000" />
|
237 |
<workItem from="1706176033980" duration="1344000" />
|
238 |
<workItem from="1706274709532" duration="27000" />
|
239 |
-
<workItem from="1706445222599" duration="
|
|
|
240 |
</task>
|
241 |
<task id="LOCAL-00001" summary="init commit">
|
242 |
<option name="closed" value="true" />
|
@@ -446,7 +449,15 @@
|
|
446 |
<option name="project" value="LOCAL" />
|
447 |
<updated>1706152276670</updated>
|
448 |
</task>
|
449 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
<servers />
|
451 |
</component>
|
452 |
<component name="TypeScriptGeneratedFilesManager">
|
@@ -490,19 +501,15 @@
|
|
490 |
<MESSAGE value="fix confidence" />
|
491 |
<MESSAGE value="IoU evaluator" />
|
492 |
<MESSAGE value="Update UI" />
|
493 |
-
<
|
|
|
494 |
</component>
|
495 |
<component name="XDebuggerManager">
|
496 |
<breakpoint-manager>
|
497 |
<breakpoints>
|
498 |
-
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
499 |
-
<url>file:///opt/homebrew/anaconda3/envs/detector/lib/python3.10/site-packages/ultralytics/data/utils.py</url>
|
500 |
-
<line>311</line>
|
501 |
-
<option name="timeStamp" value="9" />
|
502 |
-
</line-breakpoint>
|
503 |
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
504 |
<url>file://$PROJECT_DIR$/evaluator.py</url>
|
505 |
-
<line>
|
506 |
<option name="timeStamp" value="17" />
|
507 |
</line-breakpoint>
|
508 |
</breakpoints>
|
@@ -512,7 +519,7 @@
|
|
512 |
<SUITE FILE_PATH="coverage/detector$yolo_dataset.coverage" NAME="yolo_dataset Coverage Results" MODIFIED="1705852113469" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
513 |
<SUITE FILE_PATH="coverage/detector$evaluator.coverage" NAME="evaluator Coverage Results" MODIFIED="1706107083258" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
514 |
<SUITE FILE_PATH="coverage/detector$demo.coverage" NAME="demo Coverage Results" MODIFIED="1706108414052" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
515 |
-
<SUITE FILE_PATH="coverage/detector$streamlit.coverage" NAME="streamlit Coverage Results" MODIFIED="
|
516 |
<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$" />
|
517 |
</component>
|
518 |
</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="fix runtime error in coco 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$/evaluator.py" beforeDir="false" afterPath="$PROJECT_DIR$/evaluator.py" afterDir="false" />
|
11 |
+
<change beforePath="$PROJECT_DIR$/yolo_dataset.py" beforeDir="false" afterPath="$PROJECT_DIR$/yolo_dataset.py" afterDir="false" />
|
12 |
</list>
|
13 |
<option name="SHOW_DIALOG" value="false" />
|
14 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
|
57 |
<option name="hideEmptyMiddlePackages" value="true" />
|
58 |
<option name="showLibraryContents" value="true" />
|
59 |
</component>
|
60 |
+
<component name="PropertiesComponent">{
|
61 |
+
"keyToString": {
|
62 |
+
"Python.demo.executor": "Debug",
|
63 |
+
"Python.evaluator.executor": "Debug",
|
64 |
+
"Python.extract.executor": "Run",
|
65 |
+
"Python.streamlit.executor": "Debug",
|
66 |
+
"Python.yolo_dataset.executor": "Run",
|
67 |
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
68 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
69 |
+
"git-widget-placeholder": "main",
|
70 |
+
"last_opened_file_path": "/Users/famer.me/PycharmProjects/detector/tests",
|
71 |
+
"node.js.detected.package.eslint": "true",
|
72 |
+
"node.js.detected.package.tslint": "true",
|
73 |
+
"node.js.selected.package.eslint": "(autodetect)",
|
74 |
+
"node.js.selected.package.tslint": "(autodetect)",
|
75 |
+
"nodejs_package_manager_path": "npm",
|
76 |
+
"settings.editor.selected.configurable": "settings.qodana",
|
77 |
+
"vue.rearranger.settings.migration": "true"
|
78 |
}
|
79 |
+
}</component>
|
80 |
<component name="RecentsManager">
|
81 |
<key name="CopyFile.RECENT_KEYS">
|
82 |
<recent name="$PROJECT_DIR$/tests" />
|
|
|
238 |
<workItem from="1706151430872" duration="1470000" />
|
239 |
<workItem from="1706176033980" duration="1344000" />
|
240 |
<workItem from="1706274709532" duration="27000" />
|
241 |
+
<workItem from="1706445222599" duration="1814000" />
|
242 |
+
<workItem from="1706449264770" duration="4885000" />
|
243 |
</task>
|
244 |
<task id="LOCAL-00001" summary="init commit">
|
245 |
<option name="closed" value="true" />
|
|
|
449 |
<option name="project" value="LOCAL" />
|
450 |
<updated>1706152276670</updated>
|
451 |
</task>
|
452 |
+
<task id="LOCAL-00027" summary="fix runtime error in coco evaluator">
|
453 |
+
<option name="closed" value="true" />
|
454 |
+
<created>1706446725139</created>
|
455 |
+
<option name="number" value="00027" />
|
456 |
+
<option name="presentableId" value="LOCAL-00027" />
|
457 |
+
<option name="project" value="LOCAL" />
|
458 |
+
<updated>1706446725139</updated>
|
459 |
+
</task>
|
460 |
+
<option name="localTasksCounter" value="28" />
|
461 |
<servers />
|
462 |
</component>
|
463 |
<component name="TypeScriptGeneratedFilesManager">
|
|
|
501 |
<MESSAGE value="fix confidence" />
|
502 |
<MESSAGE value="IoU evaluator" />
|
503 |
<MESSAGE value="Update UI" />
|
504 |
+
<MESSAGE value="fix runtime error in coco evaluator" />
|
505 |
+
<option name="LAST_COMMIT_MESSAGE" value="fix runtime error in coco evaluator" />
|
506 |
</component>
|
507 |
<component name="XDebuggerManager">
|
508 |
<breakpoint-manager>
|
509 |
<breakpoints>
|
|
|
|
|
|
|
|
|
|
|
510 |
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
511 |
<url>file://$PROJECT_DIR$/evaluator.py</url>
|
512 |
+
<line>77</line>
|
513 |
<option name="timeStamp" value="17" />
|
514 |
</line-breakpoint>
|
515 |
</breakpoints>
|
|
|
519 |
<SUITE FILE_PATH="coverage/detector$yolo_dataset.coverage" NAME="yolo_dataset Coverage Results" MODIFIED="1705852113469" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
520 |
<SUITE FILE_PATH="coverage/detector$evaluator.coverage" NAME="evaluator Coverage Results" MODIFIED="1706107083258" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
521 |
<SUITE FILE_PATH="coverage/detector$demo.coverage" NAME="demo Coverage Results" MODIFIED="1706108414052" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
522 |
+
<SUITE FILE_PATH="coverage/detector$streamlit.coverage" NAME="streamlit Coverage Results" MODIFIED="1706453912106" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
523 |
<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$" />
|
524 |
</component>
|
525 |
</project>
|
demo.py
CHANGED
@@ -49,11 +49,11 @@ def evaluate(model: YoloModel):
|
|
49 |
if buffer:
|
50 |
with st.spinner('Wait for it...'):
|
51 |
# Slider for changing confidence
|
52 |
-
confidence = st.slider('Confidence Threshold', 0, 100, 30)
|
53 |
yolo_dataset = YoloDataset.from_zip_file(ZipFile(buffer))
|
54 |
-
capture_output(evaluator.coco_evaluate)(model=model,
|
55 |
-
|
56 |
-
|
57 |
with evaluator.yolo_evaluator(model, yolo_dataset) as metrics:
|
58 |
st.subheader("Metrics:")
|
59 |
st.write("Speed: ")
|
|
|
49 |
if buffer:
|
50 |
with st.spinner('Wait for it...'):
|
51 |
# Slider for changing confidence
|
52 |
+
# confidence = st.slider('Confidence Threshold', 0, 100, 30)
|
53 |
yolo_dataset = YoloDataset.from_zip_file(ZipFile(buffer))
|
54 |
+
# capture_output(evaluator.coco_evaluate)(model=model,
|
55 |
+
# dataset=yolo_dataset,
|
56 |
+
# confidence_threshold=confidence / 100.0)
|
57 |
with evaluator.yolo_evaluator(model, yolo_dataset) as metrics:
|
58 |
st.subheader("Metrics:")
|
59 |
st.write("Speed: ")
|
evaluator.py
CHANGED
@@ -17,23 +17,20 @@ def coco_evaluate(model: YoloModel, dataset: YoloDataset, confidence_threshold=0
|
|
17 |
evaluator = CocoEvaluator(coco_gt=coco_gt, iou_types=["bbox"])
|
18 |
|
19 |
print("Running evaluation...")
|
|
|
|
|
20 |
for image_id, annotations in tqdm(coco_gt.imgToAnns.items()):
|
21 |
# get the inputs
|
22 |
image = coco_gt.imgs[image_id]
|
23 |
results = model.model(source=dataset.load_image(image["file_name"]))
|
24 |
for result in results:
|
25 |
-
coco_anns
|
26 |
-
|
27 |
-
if len(coco_anns) == 0:
|
28 |
-
continue
|
29 |
-
evaluator.update(coco_anns)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
evaluator.accumulate()
|
36 |
-
evaluator.summarize()
|
37 |
|
38 |
|
39 |
def yolo_evaluator(model: YoloModel, dataset: YoloDataset):
|
@@ -60,9 +57,8 @@ class Metrics:
|
|
60 |
def yolo_boxes_to_coco_annotations(image_id: int, yolo_boxes, confidence_threshold=0.6):
|
61 |
return [
|
62 |
{
|
63 |
-
"image_id": image_id,
|
64 |
-
"category_id": box.cls.tolist()[0],
|
65 |
-
"area": box.xywh.tolist()[0][2] * box.xywh.tolist()[0][3],
|
66 |
"bbox": box.xywh.tolist()[0],
|
67 |
"score": box.conf.tolist()[0],
|
68 |
}
|
|
|
17 |
evaluator = CocoEvaluator(coco_gt=coco_gt, iou_types=["bbox"])
|
18 |
|
19 |
print("Running evaluation...")
|
20 |
+
coco_anns = []
|
21 |
+
|
22 |
for image_id, annotations in tqdm(coco_gt.imgToAnns.items()):
|
23 |
# get the inputs
|
24 |
image = coco_gt.imgs[image_id]
|
25 |
results = model.model(source=dataset.load_image(image["file_name"]))
|
26 |
for result in results:
|
27 |
+
coco_anns.extend(yolo_boxes_to_coco_annotations(image_id, result.boxes,
|
28 |
+
confidence_threshold=confidence_threshold))
|
|
|
|
|
|
|
29 |
|
30 |
+
evaluator.update(coco_anns)
|
31 |
+
evaluator.synchronize_between_processes()
|
32 |
+
evaluator.accumulate()
|
33 |
+
evaluator.summarize()
|
|
|
|
|
34 |
|
35 |
|
36 |
def yolo_evaluator(model: YoloModel, dataset: YoloDataset):
|
|
|
57 |
def yolo_boxes_to_coco_annotations(image_id: int, yolo_boxes, confidence_threshold=0.6):
|
58 |
return [
|
59 |
{
|
60 |
+
"image_id": int(image_id),
|
61 |
+
"category_id": int(box.cls.tolist()[0]),
|
|
|
62 |
"bbox": box.xywh.tolist()[0],
|
63 |
"score": box.conf.tolist()[0],
|
64 |
}
|
yolo_dataset.py
CHANGED
@@ -87,15 +87,20 @@ class YoloImage:
|
|
87 |
def to_coco_annotations(self, image_id: int, ann_id_start: int) -> list[coco_annotation]:
|
88 |
ann_id = ann_id_start
|
89 |
annotations: list[coco_annotation] = []
|
|
|
90 |
for label in self.labels:
|
91 |
ann_id = ann_id + 1
|
92 |
annotations.append({
|
93 |
"id": ann_id,
|
94 |
"image_id": image_id,
|
95 |
"category_id": label['class_id'],
|
96 |
-
"area": label['width'] * label['height'],
|
97 |
-
"bbox": [
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
"iscrowd": False,
|
100 |
})
|
101 |
return annotations
|
|
|
87 |
def to_coco_annotations(self, image_id: int, ann_id_start: int) -> list[coco_annotation]:
|
88 |
ann_id = ann_id_start
|
89 |
annotations: list[coco_annotation] = []
|
90 |
+
|
91 |
for label in self.labels:
|
92 |
ann_id = ann_id + 1
|
93 |
annotations.append({
|
94 |
"id": ann_id,
|
95 |
"image_id": image_id,
|
96 |
"category_id": label['class_id'],
|
97 |
+
"area": label['width'] * label['height'] * self.image.width * self.image.height,
|
98 |
+
"bbox": [
|
99 |
+
(label['x_center'] - label['width'] / 2) * self.image.width,
|
100 |
+
(label['y_center'] - label['height'] / 2) * self.image.height,
|
101 |
+
label['width'] * self.image.width,
|
102 |
+
label['height'] * self.image.height
|
103 |
+
],
|
104 |
"iscrowd": False,
|
105 |
})
|
106 |
return annotations
|