diff --git a/cam_face_landmarks.py b/cam_face_landmarks.py new file mode 100644 index 0000000..4511e6b --- /dev/null +++ b/cam_face_landmarks.py @@ -0,0 +1,25 @@ +import dlib +import cv2 + +predictor_path = "shape_predictor_68_face_landmarks.dat" +feed = cv2.VideoCapture(0) +print feed.read()[1].shape +detector = dlib.get_frontal_face_detector() +predictor = dlib.shape_predictor(predictor_path) +win = dlib.image_window() + +while True: + img = feed.read()[1] + win.clear_overlay() + win.set_image(img) + + dets = detector(img, 1) + print("Number of faces detected: {}".format(len(dets))) + for k, d in enumerate(dets): + print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(k, d.left(), d.top(), d.right(), d.bottom())) + shape = predictor(img, d) + print("Part 0: {}, Part 1: {} ...".format(shape.part(0),shape.part(1))) + win.add_overlay(shape) + print("") + win.add_overlay(dets) + dlib.hit_enter_to_continue() \ No newline at end of file diff --git a/codes/Co-training_.py b/codes/Co-training_.py new file mode 100644 index 0000000..9d60662 --- /dev/null +++ b/codes/Co-training_.py @@ -0,0 +1,86 @@ +''' +Co-Training Semi-Supervised Learning Approach on CK+ dataset + +# Libraries Used + pandas, sklearn, numpy + +# Variables + clf_svm : SVM classifier + df : pandas dataframe + df_labelled : Dataframe of labelled data + df_unlabelled : Dataframe of unlabelled data + X : inputs + y : labels + pred : predictions + k : Parameter for co-training +''' + +# Libraries used +import pandas as pd # To read database +from sklearn.cross_validation import train_test_split # To split database +from sklearn.metrics import accuracy_score, precision_recall_fscore_support # Result of model on database +import numpy as np # Mathematical analysis +from sklearn.svm import SVC # To apply SVM +from sklearn.grid_search import GridSearchCV # For Hyperparameter tuning + +param_grid = { + 'C': [1e-2, 1e-1, 1e0, 1e2, 1e1, 1e3, 5e3, 1e4, 5e4,1e5,450000], + 'kernel': ['linear', 'rbf'] + } + +clf_svm1 = GridSearchCV(SVC(), param_grid) # Classifier 1 +clf_svm2 = GridSearchCV(SVC(), param_grid) # Classifier 2 + +# Read database +df = pd.read_csv("emotion.csv",header=0) +df = df.drop(["Person Id", "Person SubID"],axis=1) +df_labelled = df[df["Emotion"]!=-1] +df_unlabelled = df[df["Emotion"]==-1] + +# Seperate labelled and unlabelled data +y_labelled = df_labelled["Emotion"] +X_labelled = df_labelled.drop(["Emotion"],axis=1) + +y_unlabelled = df_unlabelled["Emotion"] +X_unlabelled = df_unlabelled.drop(["Emotion"],axis=1) + +#COTRAINING +k=4 +X_train1, X_train2, y_train1, y_train2 = train_test_split(np.array(X_labelled),np.array(y_labelled),test_size=0.5,random_state=42) +length1=X_unlabelled.shape[0] +X_u=np.array(X_unlabelled) +X_unlabelled1=np.array(X_u[0:(length1/2)]) +X_unlabelled2=np.array(X_u[(length1/2):]) +np.random.shuffle(X_unlabelled1) +np.random.shuffle(X_unlabelled2) + +low,high=0,k +while(low