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 operator import itemgetter | |
x = [[1, 4], [3, 2]] | |
max(x, key=itemgetter(0)) | |
# >> [3, 2] | |
max(x, key=itemgetter(1)) | |
# >> [1, 4] |
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 List | |
import pandas as pd | |
def one_hot_to_categorical(df: pd.DataFrame, one_hot_features: List[str], new_feature: str, rm_ori: bool = False) -> pd.DataFrame: | |
""" | |
One Hot Encoding to Categorical Feature | |
""" | |
return_df = df.copy() | |
one_hot_df = return_df.loc[:, one_hot_features].astype(bool) | |
for row in range(len(one_hot_df)): |
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
#!/usr/bin/env python | |
from WebcamVideoStream import WebcamVideoStream | |
import cv2 | |
import time | |
from flask import Flask, render_template, Response | |
app = Flask(__name__) | |
first_flag = True | |
vs = None |
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 cv2 | |
import numpy as np | |
import argparse | |
def rescale_frame(frame, scale=2): | |
width = int(frame.shape[1] * scale) | |
height = int(frame.shape[0] * scale) | |
dim = (width, height) | |
return cv2.resize(frame, dim, interpolation=cv2.INTER_AREA) |
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 cv2 | |
import numpy as np | |
def xyxy_to_xywh(xyxy): | |
""" | |
Convert XYXY format (x,y top left and x,y bottom right) to XYWH format (x,y center point and width, height). | |
:param xyxy: [X1, Y1, X2, Y2] | |
:return: [X, Y, W, H] | |
""" | |
if np.array(xyxy).ndim > 1 or len(xyxy) > 4: |
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 cv2 | |
import numpy as np | |
def point_perspective_transform(point, matrix): | |
""" | |
Perspective transform a point given the transformation matrix | |
:param point: [X, Y] point to be transformed | |
:param matrix: 3x3 transformation matrix | |
:return: [X, Y] transformed point |
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 cv2 | |
import numpy as np | |
def rescale_frame(frame, percent=75): | |
width = int(frame.shape[1] * percent / 100) | |
height = int(frame.shape[0] * percent / 100) | |
dim = (width, height) | |
return cv2.resize(frame, dim, interpolation=cv2.INTER_AREA) |
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 shutil | |
import os | |
import random | |
def move_ext(src, dst, ext): | |
""" | |
Move file based on its extension | |
:param src: file source path | |
:param dst: file destination path |
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 torch | |
print('Torch CUDA Current Device: {}'.format(torch.cuda.current_device())) | |
print('Torch CUDA Device: {}'.format(torch.cuda.device(torch.cuda.current_device()))) | |
print('Torch CUDA Device Count: {}'.format(torch.cuda.device_count())) | |
print('Torch CUDA Device Name: {}'.format(torch.cuda.get_device_name(torch.cuda.current_device()))) | |
print('Torch CUDA Availability: {}'.format(torch.cuda.is_available())) |