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
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)) |
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
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)) |
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 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) |
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
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() |
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
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) |
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 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)) |
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
hist = model.fit(x_train, y_train, batch_size=128, epochs=70, validation_data=(x_test, y_test)) |
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
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) |
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
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() |
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
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() |