mingyang91 commited on
Commit
1d08b5b
·
verified ·
1 Parent(s): d21cbff

fix runtime error in coco evaluator

Browse files
Files changed (4) hide show
  1. .idea/workspace.xml +37 -30
  2. demo.py +4 -4
  3. evaluator.py +10 -14
  4. 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="Update UI">
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"><![CDATA[{
59
- "keyToString": {
60
- "Python.demo.executor": "Debug",
61
- "Python.evaluator.executor": "Debug",
62
- "Python.extract.executor": "Run",
63
- "Python.streamlit.executor": "Debug",
64
- "Python.yolo_dataset.executor": "Run",
65
- "RunOnceActivity.OpenProjectViewOnStart": "true",
66
- "RunOnceActivity.ShowReadmeOnStart": "true",
67
- "git-widget-placeholder": "main",
68
- "last_opened_file_path": "/Users/famer.me/PycharmProjects/detector/tests",
69
- "node.js.detected.package.eslint": "true",
70
- "node.js.detected.package.tslint": "true",
71
- "node.js.selected.package.eslint": "(autodetect)",
72
- "node.js.selected.package.tslint": "(autodetect)",
73
- "nodejs_package_manager_path": "npm",
74
- "settings.editor.selected.configurable": "settings.qodana",
75
- "vue.rearranger.settings.migration": "true"
76
  }
77
- }]]></component>
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="1467000" />
 
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
- <option name="localTasksCounter" value="27" />
 
 
 
 
 
 
 
 
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
- <option name="LAST_COMMIT_MESSAGE" value="Update UI" />
 
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>81</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="1706446389552" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
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
+ &quot;keyToString&quot;: {
62
+ &quot;Python.demo.executor&quot;: &quot;Debug&quot;,
63
+ &quot;Python.evaluator.executor&quot;: &quot;Debug&quot;,
64
+ &quot;Python.extract.executor&quot;: &quot;Run&quot;,
65
+ &quot;Python.streamlit.executor&quot;: &quot;Debug&quot;,
66
+ &quot;Python.yolo_dataset.executor&quot;: &quot;Run&quot;,
67
+ &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
68
+ &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
69
+ &quot;git-widget-placeholder&quot;: &quot;main&quot;,
70
+ &quot;last_opened_file_path&quot;: &quot;/Users/famer.me/PycharmProjects/detector/tests&quot;,
71
+ &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
72
+ &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
73
+ &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
74
+ &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
75
+ &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
76
+ &quot;settings.editor.selected.configurable&quot;: &quot;settings.qodana&quot;,
77
+ &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
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
- 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: ")
 
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 = yolo_boxes_to_coco_annotations(image_id, result.boxes,
26
- confidence_threshold=confidence_threshold)
27
- if len(coco_anns) == 0:
28
- continue
29
- evaluator.update(coco_anns)
30
 
31
- if len(evaluator.eval_imgs["bbox"]) == 0:
32
- print("No detections!")
33
- else:
34
- evaluator.synchronize_between_processes()
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": [label['x_center'] - label['width'] / 2, label['y_center'] - label['height'] / 2,
98
- label['width'], label['height']],
 
 
 
 
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