소스 검색

delete redundant files

Asriel Xu 10 달 전
부모
커밋
de53ce7520
2개의 변경된 파일과 0개의 추가작업 그리고 286개의 파일을 삭제
  1. 0 165
      tasks/Hyakkiyakou/agent/agent_ori.py
  2. 0 121
      tasks/Hyakkiyakou/agent/focus_ori.py

+ 0 - 165
tasks/Hyakkiyakou/agent/agent_ori.py

@@ -1,165 +0,0 @@
-import cv2
-import time
-import copy
-import numpy as np
-
-from datetime import datetime
-from pathlib import Path
-from numpy import uint8, fromfile
-from cached_property import cached_property
-
-from oashya.tracker import Tracker
-from oashya.labels import CLASSINDEX as CI
-from oashya.labels import id2label, id2name
-from module.logger import logger
-from tasks.Hyakkiyakou.agent.focus import Focus
-from tasks.Hyakkiyakou.debugger import Debugger
-
-
-def generate_gaussian_patch(size=(300, 300), mean=0, std_dev=60):
-    x = np.linspace(-150, 150, size[1])
-    y = np.linspace(-150, 150, size[0])
-    x, y = np.meshgrid(x, y)
-    z = np.exp(-(((x - mean) ** 2 + (y - mean) ** 2) / (2 * std_dev ** 2)))
-    return z
-
-
-def embed_patch_in_canvas(canvas, patch, position=(0, 0), patch_size=(300, 300)):
-    canvas_height, canvas_width = 720, 1280
-    patch_height, patch_width = patch_size
-    pos_x, pos_y = position
-    pos_x = max(0, min(pos_x, canvas_width))
-    pos_y = max(0, min(pos_y, canvas_width))
-
-    x1 = pos_x - patch_width // 2
-    y1 = pos_y - patch_height // 2
-    x2 = pos_x + patch_width // 2
-    y2 = pos_y + patch_height // 2
-    x1 = max(0, x1)
-    y1 = max(0, y1)
-    x2 = min(canvas_width, x2)
-    y2 = min(canvas_height, y2)
-    embed_w = x2 - x1
-    embed_h = y2 - y1
-    if embed_w <= 0 or embed_h <= 0:
-        logger.warning(f'Cannot embed patch in canvas: ({position})')
-        return canvas
-    if embed_w < patch_width or embed_h < patch_height:
-        _patch = patch[:embed_h, :embed_w]
-    else:
-        _patch = patch
-    # Embed the patch in the canvas
-    canvas[y1:y2, x1:x2] += _patch
-    return canvas
-
-
-class Agent:
-    GAUSSIAN = generate_gaussian_patch()
-    OBSERVE_THRESHOLD = 0.6
-    # --------------------------------------------------------------------------------
-
-    def __init__(self, strategy: dict = None):
-        self.z = np.zeros((720, 1280), dtype=np.float32)
-        self.focus: Focus = None
-        # 
-        strategy: dict = strategy if strategy is not None else {
-            # 'weights': [1., 1., 1., 0.6, 0.3, 0.3],
-            'priorities': [],
-            'invite_friend': False,
-            'auto_bean': False
-        }
-        self.strategy = strategy
-        self.weights: list[float] = strategy.get('weights', [1., 1., 0.7, 0.3, 0., 0.])
-        self.priorities: list[int] = strategy.get('priorities', [])
-        self.invite_friend: bool = strategy.get('invite_friend', False)
-        self.auto_bean: bool = strategy.get('auto_bean', False)
-        #
-        self.last_throw_time = datetime.now()
-        self.dbg_throw: int = 0
-        self.dbg_throw_n: int = 0
-
-    @classmethod
-    def gamma(cls, tracks: list[tuple],
-              weights: list[float],
-              priorities: list[int] = []) -> np.ndarray:
-        """
-        @param tracks:
-        @param weights: sp, ssr, sr, r, n, g
-        @param priorities:
-        @return:
-        """
-        z = np.zeros((720, 1280), dtype=np.float32)
-        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
-            weight = 1.
-            mu = 0.8 + (_cx * 0.2) / 1280
-            match _class:
-                case _ if CI.MIN_G <= _class <= CI.MAX_G: weight = weights[5]
-                case _ if CI.MIN_N <= _class <= CI.MAX_N: weight = weights[4]
-                case _ if _class != CI.R_008 and _class != CI.R_007 and (CI.MIN_R <= _class <= CI.MAX_R):
-                    weight = weights[3]  # 不要童男童女
-                case _ if CI.MIN_SR <= _class <= CI.MAX_SR: weight = weights[2]
-                case _ if CI.MIN_SSR <= _class <= CI.MAX_SSR: weight = 1.5 * weights[1]
-                case _ if CI.MIN_SP <= _class <= CI.MAX_SP: weight = 1.5 * weights[0]
-                case CI.BUFF_005:  # freeze
-                    weight = -1.
-                    _cy += 100
-                case _: continue
-            for priority in priorities:  # 我的代码在你之上
-                if priority == _class:
-                    weight = 1.7
-                    break
-            if weight == 0.:
-                continue
-            z = embed_patch_in_canvas(canvas=z, patch=(mu * weight) * Agent.GAUSSIAN, position=(_cx, _cy))
-        return z
-
-    @classmethod
-    def argmax_gamma(cls, z: np.ndarray, tracks: list[tuple]) -> Focus:
-        max_y, max_x = np.unravel_index(np.argmax(z), z.shape)
-        max_variance = 2000
-        max_index = -1
-        for index, track in enumerate(tracks):
-            _id, _class, _conf, _cx, _cy, _w, _h, _v = track
-            variance = (max_x - _cx)**2 + (max_y - _cy)**2
-            if variance < max_variance:
-                max_index = index
-                max_variance = variance
-        return Focus(inputs=tracks[max_index])
-
-    def decision(self, tracks: list[tuple], state: list) -> list:
-        not_decision = [-1, -1, False, -1]
-        if not tracks:
-            return not_decision
-        # Cache the time interval for scattering beans
-        new_time = datetime.now()
-        delta_time = 1000 * (new_time - self.last_throw_time).total_seconds()  # ms
-        self.check_observe(tracks=tracks)
-        if self.focus is None:
-            return not_decision
-        result = self.focus.decision(tracks=tracks, strategy=self.strategy, state=[delta_time] + state)
-        if result[2]:
-            self.last_throw_time = new_time
-            self.dbg_throw += 1
-        else:
-            self.dbg_throw_n += 1
-        return result
-
-    def check_observe(self, tracks: list[tuple]):
-        z = Agent.gamma(tracks=tracks, weights=self.weights, priorities=self.priorities)
-        focus = Agent.argmax_gamma(z=z, tracks=tracks)
-        omega = focus.omega(z)
-        if omega < self.OBSERVE_THRESHOLD:
-            if self.focus is not None:
-                logger.info(f'Focus disappear')
-            self.focus = None
-            return
-        if self.focus is None or self.focus != focus:
-            logger.info(f'Focus changed, now: {id2name(focus._class)}')
-            self.focus = focus
-            self.focus.set_omega(omega)
-        elif self.focus == focus:
-            self.focus.update(focus)
-            self.focus.set_omega(omega)
-        # if Debugger.info_enable:
-        #     self.focus.show()
-

+ 0 - 121
tasks/Hyakkiyakou/agent/focus_ori.py

@@ -1,121 +0,0 @@
-import numpy as np
-
-from rich.table import Table
-from rich.text import Text
-from cached_property import cached_property
-
-from module.logger import logger
-
-from oashya.labels import id2label, id2name
-from oashya.labels import CLASSINDEX as CI
-
-
-class Focus:
-    def __init__(self, inputs: list[tuple]):
-        self._id: int = inputs[0]
-        self._class: int = inputs[1]
-        self._conf: int = inputs[2]
-        self._cx: int = inputs[3]
-        self._cy: int = inputs[4]
-        self._w: int = inputs[5]
-        self._h: int = inputs[6]
-        self._v: float = inputs[7]
-        # -----------------------
-        self._omega: float = 0.
-        self._omega_buff: float = 0.
-
-    def __eq__(self, o):
-        return self._id == o._id or o._class == self._class
-
-    def __str__(self):
-        return f"""
-id: {self._id}
-class: {self._class}
-label: {id2label(self._class)}
-name: {id2name(self._class)}
-conf: {self._conf}
-xywh: ({self._cx}, {self._cy}, {self._w}, {self._h})
-velocity: {self._v}"""
-
-    def omega(self, z):
-        __omega = z[self._cy, self._cx]
-        self._omega = __omega
-        return __omega
-
-    def set_omega(self, value):
-        self._omega = value
-
-    def show(self):
-        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")
-        table.add_row('id', str(self._id), 'conf', str(self._conf))
-        table.add_row('class', str(self._class), 'xywh', f'({self._cx}, {self._cy}, {self._w}, {self._h})')
-        table.add_row('label', id2label(self._class), 'velocity', str(self._v))
-        table.add_row('name', f'{id2name(self._class)}', 'omega', str(self._omega))
-        logger.print(table, justify='center')
-
-    def update(self, focus):
-        self._id = focus._id
-        self._class = focus._class
-        self._conf = focus._conf
-        self._cx = focus._cx
-        self._cy = focus._cy
-        self._w = focus._w
-        self._h = focus._h
-        self._v = focus._v
-
-    def decision(self, tracks, strategy, state) -> list:
-
-        buff_omega, buff_cx, buff_cy, buff_v, buff_class = self.omega_buff(tracks, strategy['invite_friend'])
-        if self._omega > buff_omega:
-            buffed = False
-            target_x = self._cx + self._v * 100 - (self._w // 2)
-            target_y = self._cy - 40
-        else:
-            buffed = True
-            target_x = buff_cx + buff_v * 100
-            target_y = buff_cy - 40  # top left corner
-
-        _r = self.r(vector=state, omega=self._omega, omega_buff=self._omega_buff)
-        throw = True if _r > 0 else False
-        # x, y, throw, number
-        return [target_x, target_y, throw, 10]
-
-    def omega_buff(self, tracks, invite_friend: bool) -> float:
-        max_omega = 0.
-        max_cx = 0
-        max_cy = 0
-        max_v = 0
-        max_class = 0
-
-        for _id, _class, _conf, _cx, _cy, _w, _h, _v in tracks:
-            _current_omega = 0.
-            match _class:
-                case CI.BUFF_004: _current_omega = 2.2
-                case CI.BUFF_006: _current_omega = 2.0
-                case CI.BUFF_007: _current_omega = 2.0 if invite_friend and _cx <= 1000 else 0
-                case CI.BUFF_002: _current_omega = 2.0 if self._omega >= 1.5 else 0
-                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 else 0
-                case CI.BUFF_003: _current_omega = 2.0 if self._omega >= 1.5 and _cx <= 640 else 0
-                case _: pass
-            if _current_omega > max_omega:
-                max_omega = _current_omega
-                max_cx = _cx
-                max_cy = _cy
-                max_v = _v
-                max_class = _class
-        return max_omega, max_cx, max_cy, max_v, max_class
-            
-    @classmethod
-    def r(cls, vector: list, omega: float, omega_buff: float) -> float:
-        _omega = max(omega, omega_buff)
-        tau = - 140 / (max(101, vector[0]) - 100)
-        upsilon = (vector[1] / 250 - vector[2] / 35)
-        upsilon = 100 * (upsilon**2 if upsilon > 0 else - upsilon**2)
-        result = _omega + tau + upsilon - 0.6
-        # print(f"total: {result:.4f} | {_omega:.4f} | {tau:.4f} | {upsilon:.4f}")
-        return result
-