This file contains hidden or 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
# Splitting male data into train and test | |
test_male_data = male_data.iloc[-3:,:] | |
train_male_data = male_data.iloc[:-3,:] |
This file contains hidden or 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
# Separating female labels | |
female_data = labels[labels['Gender'] == 1] | |
female_data.head() |
This file contains hidden or 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
# Splitting male data into train and test | |
test_female_data = female_data.iloc[-3:,:] | |
train_female_data = female_data.iloc[:-3,:] |
This file contains hidden or 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
# Displaying image | |
img=mpimg.imread('final/Raw_0016_011_20050913100034_Portrait.png') | |
imgplot = plt.imshow(img) | |
plt.show() |
This file contains hidden or 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
# total test data | |
test_indices = test_female_data.index.tolist() + test_male_data.index.tolist() | |
test_data = labels.iloc[test_indices,:] | |
test_data.head() |
This file contains hidden or 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
# total train data | |
train_data = pd.concat([labels, test_data, test_data]).drop_duplicates(keep=False) | |
train_data.head() |
This file contains hidden or 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 and test with image name along with paths | |
path = '/final/' # path of your image folder | |
train_image_name = [path+each for each in train_data['Filename'].values.tolist()] | |
test_image_name = [path+each for each in test_data['Filename'].values.tolist()] |
This file contains hidden or 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
# preparing data by processing images using opencv | |
ROWS = 64 | |
COLS = 64 | |
CHANNELS = 3 | |
def read_image(file_path): | |
img = cv2.imread(file_path, cv2.IMREAD_COLOR) #cv2.IMREAD_GRAYSCALE | |
return cv2.resize(img, (ROWS, COLS), interpolation=cv2.INTER_CUBIC) | |
This file contains hidden or 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
# checking count of male and females | |
sns.countplot(labels['Gender'] |
This file contains hidden or 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
# plotting female and male side by side | |
def show_male_and_female(): | |
female = read_image(train_image_name[0]) | |
male = read_image(train_image_name[2]) | |
pair = np.concatenate((female, male), axis=1) | |
plt.figure(figsize=(10,5)) | |
plt.imshow(pair) | |
plt.show() | |
show_male_and_female() |