In this post we will use the OpenCV library for facial recognition. Here is an example using my webcam as an input:
The best part is that it can be done using less than 20 lines of code:
print('hello world') |
## Imports | |
from ashrae_utils import reduce_mem_usage, CyclicLR, LRFinder | |
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
import math | |
import tqdm | |
import gc | |
from sklearn.linear_model import RidgeCV | |
import seaborn as sns |
from selenium import webdriver | |
from PIL import Image | |
from io import BytesIO | |
def take_screenshot(element, driver, filename='screenshot.png'): | |
""" | |
Source: https://stackoverflow.com/questions/15018372/how-to-take-partial-screenshot-with-selenium-webdriver-in-python | |
""" | |
location = element.location_once_scrolled_into_view | |
size = element.size |
from keras.callbacks import Callback | |
import keras.backend as K | |
import numpy as np | |
import matplotlib.pyplot as plt | |
class LRFinder(Callback): | |
""" | |
Up-to date version: https://github.com/WittmannF/LRFinder | |
Example of usage: | |
from keras.models import Sequential |
import matplotlib.pyplot as plt | |
import keras.backend as K | |
from keras.callbacks import Callback | |
class LRFinder(Callback): | |
''' | |
A simple callback for finding the optimal learning rate range for your model + dataset. | |
from sklearn.datasets import make_regression | |
from sklearn.metrics import r2_score | |
import matplotlib.pyplot as plt | |
#%matplotlib inline | |
# Generate toy data | |
X, y, w_true = make_regression(n_samples=20, n_features=1, random_state=0, noise=1.0, coef=True) | |
w_bad = 0.5*w_true | |
w_verybad = -0.3*w_true |
import os | |
def rename_dir(path,sufix,extension_searched): | |
for file_name in os.listdir(path): | |
file_name_without_ext = os.path.splitext(file_name)[0] | |
extension = os.path.splitext(file_name)[1] | |
if extension == extension_searched: | |
if file_name_without_ext.rfind(sufix) > 0: | |
new_file_name = file_name[:file_name_without_ext.rfind(sufix)] + extension_searched | |
os.rename(os.path.join(path,file_name),os.path.join(path,new_file_name)) |