Skip to content

Instantly share code, notes, and snippets.

Avatar

Jakub Adamczyk j-adamczyk

View GitHub Profile
@j-adamczyk
j-adamczyk / mtcnn_detection.py
Created Feb 16, 2021
Face detection using MTCNN
View mtcnn_detection.py
import cv2
from facenet_pytorch.models.mtcnn import MTCNN
import numpy as np
import torch
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
mtcnn = MTCNN(keep_all=True, device=device)
def mtcnn_detect(img: np.ndarray) -> np.ndarray:
@j-adamczyk
j-adamczyk / viola_jones_detection.py
Created Feb 16, 2021
Face detection using Viola-Jones method
View viola_jones_detection.py
import cv2
import numpy as np
face_cascade = cv2.CascadeClassifier()
face_cascade.load("haarcascade_frontalface_alt.xml")
def viola_jones_detect(img: np.ndarray) -> np.ndarray:
frame_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
frame_gray = cv2.equalizeHist(frame_gray)
@j-adamczyk
j-adamczyk / graphviz_disk_op.py
Created Feb 16, 2021
Plotting decision trees with Graphviz with disk operations
View graphviz_disk_op.py
import os
from typing import List
import graphviz
import matplotlib.image as plt_img
import numpy as np
from sklearn.tree import DecisionTreeClassifier, export_graphviz
def plot_disk_operations(clf: DecisionTreeClassifier,
@j-adamczyk
j-adamczyk / graphviz_in_memory.py
Created Feb 16, 2021
Plotting decision trees with Graphviz in RAM
View graphviz_in_memory.py
from typing import List
import cv2
import graphviz
import numpy as np
from sklearn.tree import DecisionTreeClassifier, export_graphviz
def plot_in_memory(clf: DecisionTreeClassifier,
feature_names: List[str],
@j-adamczyk
j-adamczyk / kmeans_with_faiss.py
Last active Nov 20, 2021
K-Means clustring with faiss library
View kmeans_with_faiss.py
import faiss
import numpy as np
class FaissKMeans:
def __init__(self, n_clusters=8, n_init=10, max_iter=300):
self.n_clusters = n_clusters
self.n_init = n_init
self.max_iter = max_iter
self.kmeans = None
@j-adamczyk
j-adamczyk / knn_with_faiss.py
Created Sep 12, 2020
k nearest neighbors classifier with faiss library
View knn_with_faiss.py
import numpy as np
import faiss
class FaissKNeighbors:
def __init__(self, k=5):
self.index = None
self.y = None
self.k = k
View detectron2_demo_1.py
import argparse
def _get_parsed_args() -> argparse.Namespace:
"""
Create an argument parser and parse arguments.
:return: parsed arguments as a Namespace object
"""
parser = argparse.ArgumentParser(description="Detectron2 demo")
@j-adamczyk
j-adamczyk / detectron2_demo_4.py
Created Jul 18, 2020
Detectron2 demo article - gist 4
View detectron2_demo_4.py
import argparse
import cv2
import numpy as np
import re
from detectron2 import model_zoo
from detectron2.config import get_cfg, CfgNode
from detectron2.data import MetadataCatalog
from detectron2.engine import DefaultPredictor
@j-adamczyk
j-adamczyk / detectron2_demo_3.py
Created Jul 18, 2020
Detectron2 demo article - gist 3
View detectron2_demo_3.py
import cv2
import numpy as np
import re
from detectron2.data import MetadataCatalog
from detectron2.structures import Instances
from detectron2.utils.visualizer import Visualizer, VisImage
if __name__ == "__main__":
@j-adamczyk
j-adamczyk / detectron2_demo_2.py
Last active Jul 18, 2020
Detectron2 demo article - gist 2
View detectron2_demo_2.py
from detectron2 import model_zoo
from detectron2.config import get_cfg, CfgNode
from detectron2.engine import DefaultPredictor
if __name__ == "__main__":
args: argparse.Namespace = _get_parsed_args()
cfg: CfgNode = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(args.base_model))