Skip to content

Instantly share code, notes, and snippets.

View hav4ik's full-sized avatar

Chan Kha Vu hav4ik

View GitHub Profile
@hav4ik
hav4ik / ndcg_vis.py
Last active August 9, 2023 22:32
Visualization scripts for "At the Core of a Search Engine: Learning to Rank" blog post.
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
sns.set()
def ndcg_at_k(ranked_relevances, k=None):
"""
Calculate NDCG for given ranked relevances.
"""
import cv2
import copy
import pycocotools.mask as mask_util
import numpy as np
class CopyPasteAugmentator:
"""Copy-paste cells from another image in the dataset
"""
def __init__(self, d2_dataset,
@hav4ik
hav4ik / geobotbeater_example.py
Last active January 30, 2021 18:58
Pseudo-python code that shows how you can incorporate the GeoBeeater with your code. This is a mere snippets for you to copy-paste and adapt it to your code.
class YourAgent:
def __init__(self,
# ... other params
# ...
antigeo_thresh=20):
# ...
# Initialize your agent here ...
# ...
@hav4ik
hav4ik / geobeater.py
Created January 30, 2021 18:13
GeoBot Beater (by Robga, modified)
import operator
import numpy as np
import cmath
from collections import namedtuple
basis = np.array([1, cmath.exp(2j * cmath.pi * 1 / 3), cmath.exp(2j * cmath.pi * 2 / 3)])
HistMatchResult = namedtuple("HistMatchResult", "idx length")
@hav4ik
hav4ik / stack_trace.md
Created August 31, 2020 22:33
stack_trace.md
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
    106   def _method_wrapper(self, *args, **kwargs):
    107     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
--> 108       return method(self, *args, **kwargs)
    109 
    110     # Running inside `run_distribute_coordinator` already.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
   1096                 batch_size=batch_size):
# These are probably the only important parameters in the
# whole pipeline (steps 0 through 3).
BLOCK_SIZE = 40
DELTA = 25
# Do the necessary noise cleaning and other stuffs.
# I just do a simple blurring here but you can optionally
# add more stuffs.
def preprocess(image):
image = cv2.medianBlur(image, 3)
@hav4ik
hav4ik / gamma_correction.py
Last active June 30, 2020 20:20
This is for my medium article
# Somehow I found the value of `gamma=1.2` to be the best in my case
def adjust_gamma(image, gamma=1.2):
# build a lookup table mapping the pixel values [0, 255] to
# their adjusted gamma values
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)
mnetv2: 601833648 FLOPs
alexnet: 2079939473 FLOPs
vgg19: 39285112688 FLOPs
vgg16: 30960211824 FLOPs
body_0: 208719616 FLOPs
mood_head: 396661522 FLOPs
roa_head: 68190732 FLOPs
art_head: 396730804 FLOPs
@hav4ik
hav4ik / guide.md
Created December 11, 2018 21:30
InstallingGuide

Install Nvidia drivers the right way

You don't want Xorg to use your NVIDIA gpu. Need to blacklist nouveau and nvidia-drm. In the created file /etc/modprobe.d/blacklist-nouveau.conf:

blacklist nouveau
options nouveau modeset=0

In the file /etc/modprobe.d/blacklist-nvidia-drm.conf:

blacklist nvidia-drm

@hav4ik
hav4ik / .vimrc
Created May 14, 2018 13:04
my vim config
" ------------------- BEGIN: VUNDLE CONFIGURATION -------------------
set nocompatible " required
filetype off " required
" set runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle handle itself, required!
Plugin 'VundleVim/Vundle.vim'