Просмотр исходного кода

feat(Hyakkiyakou): Optimize debug logs

ryland 2 лет назад
Родитель
Сommit
e74495fce0
3 измененных файлов с 31 добавлено и 21 удалено
  1. 2 2
      tasks/Hyakkiyakou/agent/agent.py
  2. 22 1
      tasks/Hyakkiyakou/debugger.py
  3. 7 18
      tasks/Hyakkiyakou/script_task.py

+ 2 - 2
tasks/Hyakkiyakou/agent/agent.py

@@ -160,6 +160,6 @@ class Agent:
         elif self.focus == focus:
             self.focus.update(focus)
             self.focus.set_omega(omega)
-        if Debugger.info_enable:
-            self.focus.show()
+        # if Debugger.info_enable:
+        #     self.focus.show()
 

+ 22 - 1
tasks/Hyakkiyakou/debugger.py

@@ -8,13 +8,15 @@ from datetime import datetime
 from cached_property import cached_property
 from pathlib import Path
 from numpy import uint8, fromfile
+from rich.table import Table
 from threading import Event, Lock, Thread
-from oashya.labels import id2label, CLASSIFY, CLASSINDEX
+from oashya.labels import id2label, CLASSIFY, CLASSINDEX, id2name
 from oashya.utils import draw_tracks
 from oashya.tracker import Tracker
 
 from tasks.base_task import BaseTask
 from module.logger import logger
+from tasks.Hyakkiyakou.agent.focus import Focus
 
 
 def test_track(show: bool = False):
@@ -169,6 +171,25 @@ class Debugger:
         image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
         cv2.imwrite(str(self.hya_save_result_folder / _now_name), image)
 
+    @classmethod
+    def show_info(cls, tracker, f: Focus):
+        table = Table(show_lines=True)
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        table.add_column('Property', header_style="bright_cyan", style="cyan", no_wrap=True)
+        table.add_column("Value", style="green")
+        if f is not None:
+            try:
+                table.add_row('id', str(f._id), 'conf', f'{f._conf:.2f}')
+                table.add_row('class', str(f._class), 'xywh', f'({f._cx}, {f._cy}, {f._w}, {f._h})')
+                table.add_row('label', id2label(f._class), 'velocity', f'{f._v:.2f}')
+                table.add_row('name', f'{id2name(f._class)}', 'omega', str(f._omega))
+            except Exception as e:
+                pass
+        table.add_row('detect cost', f'{(tracker.detect_time.total_seconds() * 1000):.2f}ms',
+                    'track cost', f'{(tracker.track_time.total_seconds() * 1000):.2f}ms')
+        logger.print(table, justify='center')
+
 
 def test_debugger():
     debugger = Debugger(info_enable=False, continuous_learning=True)

+ 7 - 18
tasks/Hyakkiyakou/script_task.py

@@ -11,7 +11,7 @@ from numpy import uint8, fromfile
 from random import choice
 from cached_property import cached_property
 # Use cmd to install: ./toolkit/python.exe -m pip install -i https://pypi.org/simple/ oashya --trusted-host pypi.org
-# update oashya:  ./toolkit/python.exe -m pip install
+# update oashya:  ./toolkit/python.exe -m pip install --upgrade oashya
 from oashya.tracker import Tracker
 from oashya.labels import label2id
 from oashya.utils import draw_tracks
@@ -67,11 +67,13 @@ class ScriptTask(GameUi, HyaSlave):
         # 这个坑后面在补
         if inf_en == 'tensorrt' or precision == 'int8':
             raise RequestHumanTakeover('Only support onnxruntime')
+        debug_info: bool = self._config.debug_config.hya_info
         args = {
             'conf_threshold': conf,
             'iou_threshold': nms,
             'precision': precision,
             'inference_engine': inf_en,
+            'debug': debug_info,
         }
         return Tracker(args=args)
 
@@ -200,6 +202,8 @@ class ScriptTask(GameUi, HyaSlave):
                 self.debugger.show_sync(image=draw_image)
             if self._config.debug_config.continuous_learning:
                 self.debugger.deal_learning(image=self.device.image, tracks=tracks)
+            if self._config.debug_config.hya_info:
+                self.debugger.show_info(tracker=self.tracker, f=self.agent.focus)
 
         logger.info('Hyakkiyakou End')
         if self._config.debug_config.hya_show:
@@ -211,6 +215,8 @@ class ScriptTask(GameUi, HyaSlave):
         self.ui_click(self.I_HEND, self.I_HACCESS)
         self.debugger.save_images()
         del self.debugger
+        # you maybe update oashya
+        self.tracker.clear_tracks()
 
     def do_action(self, action: list, state):
         x, y, throw, bean = action
@@ -221,23 +227,6 @@ class ScriptTask(GameUi, HyaSlave):
         self.fast_click(x=x, y=y)
 
 
-# def test_opencv():
-#     import timeit
-#     from module.config.config import Config
-#     from module.device.device import Device
-#
-#     c = Config('oas1')
-#     d = Device(c)
-#
-#     t = ScriptTask(c, d)
-#     t.fast_screenshot()
-#     def sh():
-#         t.device.image = cv2.cvtColor(t.device.image, cv2.COLOR_BGR2RGB)
-#     execution_time = timeit.timeit(sh, number=100)
-#     print(f"执行总的时间: {execution_time * 1000} ms")
-#     cv2.imshow('test', t.device.image)
-#     cv2.waitKey(0)
-
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device