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
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
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
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
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
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
def driver_drowsiness_detection_model(input_shape=(32, 32, 3)): | |
model = Sequential() | |
model.add(Input(shape=input_shape)) | |
model.add(Conv2D(32, (3, 3), padding='same', strides=(1, 1), name='conv1', activation='relu', | |
kernel_initializer=glorot_uniform(seed=0))) | |
model.add(BatchNormalization()) | |
model.add(Conv2D(32, (3, 3), padding='same', strides=(1, 1), name='conv2', activation='relu', | |
kernel_initializer=glorot_uniform(seed=0))) | |
model.add(BatchNormalization()) | |
model.add(Dropout(0.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
model = cv2.dnn.readNetFromTorch('udnie.t7') | |
image = cv2.imread('yuvnish malhotra photo.jpg') | |
(h, w) = image.shape[:2] | |
image = cv2.resize(image, (600, h)) | |
(h, w, c) = image.shape | |
print(h, w, c) | |
blob = cv2.dnn.blobFromImage(image, 1.0, (w, h), (103.939, 116.779, 123.680), swapRB=False, crop=False) |
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
optimizer = keras.optimizers.SGD( | |
keras.optimizers.schedules.ExponentialDecay( | |
initial_learning_rate=100.0, decay_steps=500, decay_rate=0.96 | |
) | |
) | |
base_image = preprocess_image('yuvnish malhotra photo.jpg') | |
style_reference_image = preprocess_image('style_image3.jpg') | |
combination_image = tf.Variable(preprocess_image('yuvnish malhotra photo.jpg')) | |
print(base_image.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
def compute_loss(combination_image, base_image, style_reference_image): | |
input_tensor = tf.concat( | |
[base_image, style_reference_image, combination_image], axis=0 | |
) | |
features = feature_extractor(input_tensor) | |
# Initialize the loss | |
loss = tf.zeros(shape=()) | |
# Add content loss |