Skip to content

Instantly share code, notes, and snippets.

View kumarvipu1's full-sized avatar
👋

vipul kumar kumarvipu1

👋
View GitHub Profile
@kumarvipu1
kumarvipu1 / predict.py
Last active February 3, 2021 20:45
image classifier part 5
#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
@kumarvipu1
kumarvipu1 / performance-visualization.py
Created February 3, 2021 16:36
image classifier part 5
#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')
@kumarvipu1
kumarvipu1 / implement.py
Last active February 3, 2021 13:49
image classifier part 4
#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))
@kumarvipu1
kumarvipu1 / training.py
Created February 3, 2021 01:40
image_clssifier_part3
def fitting_model(model, x, y, epoch):
model.fit(x,y, shuffle = True, epochs = epoch)
@kumarvipu1
kumarvipu1 / model-compiler.py
Last active February 3, 2021 01:38
image classifier part 3
def compile_model(model, optimizer='adam', loss='categorical_crossentropy'):
model.compile(optimizer=optimizer, loss=loss, metrics=["accuracy"])
@kumarvipu1
kumarvipu1 / covnet.py
Created February 3, 2021 00:14
image_classifier part 2
# 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),
@kumarvipu1
kumarvipu1 / import-data.py
Last active February 2, 2021 18:25
Part1 of image classifier
# 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
@kumarvipu1
kumarvipu1 / fullBody_detect.py
Created December 2, 2020 11:38
Sample code for full body detection with opencv
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")
@kumarvipu1
kumarvipu1 / face_detect.py
Last active February 12, 2024 19:13
Face Detect
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")