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
#importing and processing input image | |
import cv2 | |
img = cv2.imread("sample_img.jpg") #loading input image | |
img = cv2.resize(img, (28, 28), interpolation = cv2.INTER_AREA) #resizing to input shape | |
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #chaging to grayscale format | |
img = cv2.bitwise_not(img) #the color scale was inverted, correcting inverted color scale | |
img = cv2.Canny(img, 50, 50) # removing noise | |
predict_data = np.array([img])/255 #changing image data to array | |
predict_data = predict_data.reshape(1,28, 28, 1) #reshaping to input shape |
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
#model performance visualization | |
f = plt.figure(figsize=(20,8)) | |
#accuracy | |
plt1 = f.add_subplot(121) | |
plt1.plot(history.history['accuracy'], label = str('Training accuracy')) | |
plt1.plot(history.history['val_accuracy'], label = str('Validation accuracy')) | |
plt.legend() | |
plt.title('accuracy') |
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
#reshaping the independant variables | |
train_X = train_X.reshape(train_X.shape[0], 28, 28, 1) | |
val_X = val_X .reshape(val_X.shape[0], 28, 28, 1) | |
#encoding the dependant variable | |
train_y = np.eye(10)[train_y] | |
val_y = np.eye(10)[val_y] | |
#creating model | |
model = create_model((28,28,1)) |
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
def fitting_model(model, x, y, epoch): | |
model.fit(x,y, shuffle = True, epochs = epoch) |
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
def compile_model(model, optimizer='adam', loss='categorical_crossentropy'): | |
model.compile(optimizer=optimizer, loss=loss, metrics=["accuracy"]) |
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
# importing the libraries | |
import tensorflow.keras.layers as layers | |
from tensorflow.keras.models import Model | |
from tensorflow.keras.models import Sequential | |
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dense, Flatten | |
#defining function for building the model | |
def create_model(input_shape = (28,28,1)): | |
model = keras.Sequential([ | |
layers.Conv2D(filters = 32, kernel_size = 3, activation = 'relu', padding = 'same', input_shape = input_shape), |
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
# importing libraries | |
import numpy as np | |
from tensorflow import keras | |
from keras.datasets import mnist | |
#loading dataset | |
(train_X, train_y), (val_X, val_y) = mnist.load_data() | |
#normalizing the dataset | |
train_X, val_X = train_X/255, val_X/255 |
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 video | |
cap = cv2.VideoCapture("<path>/video.mp4") | |
cap.set(3, 640) | |
cap.set(4, 420) | |
# import cascade file for full body | |
bodyCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_fullbody.xml") |
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 | |
# Enable camera | |
cap = cv2.VideoCapture(0) | |
cap.set(3, 640) | |
cap.set(4, 420) | |
# import cascade file for facial recognition | |
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") |