Skip to content

Instantly share code, notes, and snippets.

View masouduut94's full-sized avatar
πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦
Family comes before Work.

Masoud Masoumi Moghadam masouduut94

πŸ‘¨β€πŸ‘©β€πŸ‘¦β€πŸ‘¦
Family comes before Work.
View GitHub Profile
@masouduut94
masouduut94 / setup.py
Created October 12, 2024 22:51
A minimal python file to convert the pyx file into so module.
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()],
@masouduut94
masouduut94 / evaluator.pyx
Last active October 12, 2024 22:25
cython parallelized code for bbox iou calculation
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)
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
@masouduut94
masouduut94 / taichi_evaluator.py
Created October 12, 2024 20:14
The taichi_evaluator for faster computations.
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):
@masouduut94
masouduut94 / jit_evaluator.py
Last active October 12, 2024 08:51
finding TP, FP, FN and returning annotation_id for ground_truths and predictions JSONs.
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:
"""
import json
import random
def create_test_data():
ground_truth = {
"annotations": []
}
predictions = {
"annotations": []
import json
from pathlib import Path
from typing import List, Self
class BoundingBox:
"""
Attributes:
annotation_id (int):
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
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
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()