Skip to content

Instantly share code, notes, and snippets.

View Yuvnish017's full-sized avatar

Yuvnish Malhotra Yuvnish017

View GitHub Profile
@Yuvnish017
Yuvnish017 / load_dataset.py
Created June 29, 2021 06:22
Driver Drowsiness Detection
data = np.load('dataset.npz', allow_pickle=True)
X = data['arr_0']
Y = data['arr_1']
X = list(X)
Y = list(Y)
for i in range(len(X)):
img = X[i]
img = cv2.resize(img, (32, 32))
@Yuvnish017
Yuvnish017 / training_model.py
Created June 29, 2021 06:27
Driver Drowsiness Detection
aug = ImageDataGenerator(rotation_range=20,
zoom_range=0.2,
horizontal_flip=True)
hist = model.fit(aug.flow(X_train, Y_train, batch_size=128),
batch_size=128,
epochs=200,
validation_data=(X_test, Y_test))
@Yuvnish017
Yuvnish017 / test_pipeline.py
Created June 29, 2021 06:51
Driver Drowsiness Detection
def full_face_detection_pipeline(input_image_path):
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
fa = FaceAligner(predictor, desiredFaceWidth=256)
test_image = cv2.imread(input_image_path)
test_image = imutils.resize(test_image, width=800)
test_image_gray = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
rects = detector(test_image_gray, 2)
@Yuvnish017
Yuvnish017 / test1.py
Last active June 29, 2021 06:59
Driver Drowsiness Detection
figure = plt.figure(figsize=(5, 5))
predicted_image = cv2.imread(full_face_detection_pipeline('sleepy-driver.jpg'))
predicted_image = cv2.cvtColor(predicted_image, cv2.COLOR_BGR2RGB)
plt.imshow(predicted_image)
plt.axis('off')
plt.show()
@Yuvnish017
Yuvnish017 / data_augmentaion.py
Created July 10, 2021 06:23
Parkinson_disease_detection
train_data_generator = ImageDataGenerator(rotation_range=360,
width_shift_range=0.0,
height_shift_range=0.0,
# brightness_range=[0.5, 1.5],
horizontal_flip=True,
vertical_flip=True)
x = list(x_train)
y = list(y_train)
@Yuvnish017
Yuvnish017 / defining_model.py
Created July 10, 2021 06:38
Parkinson_disease_detection
def parkinson_disease_detection_model(input_shape=(128, 128, 1)):
regularizer = tf.keras.regularizers.l2(0.001)
model = Sequential()
model.add(Input(shape=input_shape))
model.add(Conv2D(128, (5, 5), padding='same', strides=(1, 1), name='conv1', activation='relu',
kernel_initializer='glorot_uniform', kernel_regularizer=regularizer))
model.add(MaxPool2D((9, 9), strides=(3, 3)))
model.add(Conv2D(64, (5, 5), padding='same', strides=(1, 1), name='conv2', activation='relu',
kernel_initializer='glorot_uniform', kernel_regularizer=regularizer))
@Yuvnish017
Yuvnish017 / model_training.py
Created July 10, 2021 06:42
Parkinson_disease_detection
hist = model.fit(x_train, y_train, batch_size=128, epochs=70, validation_data=(x_test, y_test))
@Yuvnish017
Yuvnish017 / testing.py
Created July 10, 2021 06:49
Parkinson_disease_detection
labels = ['Healthy', 'Parkinson']
image_healthy = cv2.imread('Parkinson_disease_detection/test_image_healthy.png')
image_parkinson = cv2.imread('Parkinson_disease_detection/test_image_parkinson.png')
image_healthy = cv2.resize(image_healthy, (128, 128))
image_healthy = cv2.cvtColor(image_healthy, cv2.COLOR_BGR2GRAY)
image_healthy = np.array(image_healthy)
image_healthy = np.expand_dims(image_healthy, axis=0)
image_healthy = np.expand_dims(image_healthy, axis=-1)
@Yuvnish017
Yuvnish017 / test_image1.py
Created July 10, 2021 06:50
Parkinson_disease_detection
figure = plt.figure(figsize=(2, 2))
img_healthy = np.squeeze(image_healthy, axis=0)
plt.imshow(img_healthy)
plt.axis('off')
plt.title(f'Prediction by the model: {labels[np.argmax(ypred_healthy[0], axis=0)]}')
plt.show()
@Yuvnish017
Yuvnish017 / test_image2py
Created July 10, 2021 06:53
Parkinson_disease_detection
figure = plt.figure(figsize=(2, 2))
img_parkinson = np.squeeze(image_parkinson, axis=0)
plt.imshow(img_parkinson)
plt.axis('off')
plt.title(f'Prediction by the model: {labels[np.argmax(ypred_parkinson[0], axis=0)]}')
plt.show()