This file contains hidden or 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 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: |
This file contains hidden or 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 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) |
This file contains hidden or 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 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, |
This file contains hidden or 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 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], |
This file contains hidden or 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 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 |
This file contains hidden or 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 numpy as np | |
import faiss | |
class FaissKNeighbors: | |
def __init__(self, k=5): | |
self.index = None | |
self.y = None | |
self.k = k |
This file contains hidden or 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 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") |
This file contains hidden or 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 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 |
This file contains hidden or 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 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__": |
This file contains hidden or 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 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)) |