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
def build_deep_autoencoder(img_shape,code_size=32): | |
"""PCA's deeper brother. See instructions above""" | |
H,W,C = img_shape | |
encoder = keras.models.Sequential() | |
encoder.add(L.InputLayer(img_shape)) | |
encoder.add(L.Flatten()) | |
encoder.add(L.Dense(code_size*8, activation='relu')) | |
encoder.add(L.Dense(code_size*4, activation='tanh')) |
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
def visualize(img,encoder,decoder): | |
"""Draws original, encoded and decoded images""" | |
code = encoder.predict(img[None])[0] | |
reco = decoder.predict(code[None])[0] | |
plt.subplot(1,3,1) | |
plt.title("Original") | |
plt.imshow(img) | |
plt.subplot(1,3,2) |
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
def build_pca_autoencoder(img_shape,code_size=32): | |
""" | |
Here we define a simple linear autoencoder as described above. | |
We also flatten and un-flatten data to be compatible with image shapes | |
""" | |
encoder = keras.models.Sequential() | |
encoder.add(L.InputLayer(img_shape)) | |
encoder.add(L.Flatten()) #flatten image to vector | |
encoder.add(L.Dense(code_size)) #actual encoder |
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 os | |
import cv2 | |
import pandas as pd | |
import tarfile | |
import tqdm | |
ATTRS_NAME = "./data/lfw_attributes.txt" # http://www.cs.columbia.edu/CAVE/databases/pubfig/download/lfw_attributes.txt | |
RAW_IMAGES_NAME = "./data/lfw.tgz" # http://vis-www.cs.umass.edu/lfw/lfw.tgz |
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
train_X = np.empty((18000, 200, 200)) | |
for i in range(0,18000): | |
if i >= 3600 and i < 5400: | |
img = np.rot90(org_train_x[i].reshape(28,28),k =3, axes=(0,1)) | |
img = np.fliplr(img) | |
elif i >= 9000 and i < 10800: | |
img = np.rot90(org_train_x[i].reshape(28,28),k =3, axes=(0,1)) | |
img = np.fliplr(img) |
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 | |
from sklearn.model_selection import train_test_split | |
def get_train_test(split_ratio=0.6, random_state=42): | |
# Get available labels | |
labels, indices, _ = get_labels(DATA_PATH) | |
# Getting first arrays | |
X = np.load(labels[0] + '.npy') | |
y = np.zeros(X.shape[0]) |
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 os | |
DATA_PATH = "./data/" | |
# Input: Folder Path | |
# Output: Tuple (Label, Indices of the labels, one-hot encoded labels) | |
def get_labels(path=DATA_PATH): | |
labels = os.listdir(path) | |
label_indices = np.arange(0, len(labels)) |
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 librosa | |
def wav2mfcc(file_path, max_pad_len=11): | |
wave, sr = librosa.load(file_path, mono=True, sr=None) | |
wave = wave[::3] | |
mfcc = librosa.feature.mfcc(wave, sr=16000) | |
pad_width = max_pad_len - mfcc.shape[1] | |
mfcc = np.pad(mfcc, pad_width=((0, 0), (0, pad_width)), mode='constant') | |
return mfcc |
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
pinMode() | |
digitalRead() | |
digitalWrite() |
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 spacy | |
import pandas as pd | |
import argparse | |
import re | |
nlp = spacy.load('en') | |
# Get the name of the file | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file_path", help="Enter csv filepath here") |