π¨βπ©βπ¦βπ¦
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from setuptools import setup | |
from Cython.Build import cythonize | |
from setuptools.extension import Extension | |
import numpy as np | |
extensions = [ | |
Extension( | |
"evaluator", | |
sources=["evaluator.pyx"], | |
include_dirs=[np.get_include()], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
cimport cython | |
from cython.parallel import prange | |
from cython.view cimport array | |
import numpy as np | |
cimport numpy as np | |
np.import_array() | |
@cython.boundscheck(False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import numpy as np | |
cimport cython | |
@cython.boundscheck(False) # Turn off bounds-checking for performance | |
@cython.wraparound(False) # Turn off negative index wraparound for performance | |
cdef class Evaluator: | |
cdef float[:, :] ground_truth_boxes | |
cdef float[:, :] predicted_boxes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import taichi as ti | |
from pathlib import Path | |
from time import time | |
import json | |
ti.init(arch=ti.cpu) | |
@ti.data_oriented | |
def initialize_boxes(annotations, boxes): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
import json | |
import numpy as np | |
from numba import jit | |
from time import time | |
@jit(nogil=True, nopython=True) | |
def calculate_iou(x1, y1, x2, y2, x1_other, y1_other, x2_other, y2_other) -> float: | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import random | |
def create_test_data(): | |
ground_truth = { | |
"annotations": [] | |
} | |
predictions = { | |
"annotations": [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from pathlib import Path | |
from typing import List, Self | |
class BoundingBox: | |
""" | |
Attributes: | |
annotation_id (int): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PoolRaveMctsAgent(RaveMctsAgent): | |
def __init__(self, state: GameState = GameState(8)): | |
super().__init__(state) | |
self.black_rave = {} | |
self.white_rave = {} | |
def set_gamestate(self, state: GameState) -> None: | |
""" | |
Set the root_state of the tree to the passed gamestate, this clears all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LGRMctsAgent(RaveMctsAgent): | |
def __init__(self, state: GameState = GameState(8)): | |
super().__init__(state) | |
self.black_reply = {} | |
self.white_reply = {} | |
def set_gamestate(self, state: GameState) -> None: | |
""" | |
Set the root_state of the tree to the passed gamestate, this clears all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecisiveMoveMctsAgent(RaveMctsAgent): | |
def roll_out(self, state: GameState) -> tuple: | |
""" | |
Simulate a random game except that we play all known critical cells | |
first, return the winning player and record critical cells at the end. | |
""" | |
moves = state.moves() | |
good_moves = moves.copy() | |
good_opponent_moves = moves.copy() | |
to_play = state.turn() |