Skip to content

Instantly share code, notes, and snippets.

View techwithshadab's full-sized avatar
💻
Playing with Data

Shadab Hussain techwithshadab

💻
Playing with Data
View GitHub Profile
# Splitting male data into train and test
test_male_data = male_data.iloc[-3:,:]
train_male_data = male_data.iloc[:-3,:]
# Separating female labels
female_data = labels[labels['Gender'] == 1]
female_data.head()
# Splitting male data into train and test
test_female_data = female_data.iloc[-3:,:]
train_female_data = female_data.iloc[:-3,:]
# Displaying image
img=mpimg.imread('final/Raw_0016_011_20050913100034_Portrait.png')
imgplot = plt.imshow(img)
plt.show()
# total test data
test_indices = test_female_data.index.tolist() + test_male_data.index.tolist()
test_data = labels.iloc[test_indices,:]
test_data.head()
# total train data
train_data = pd.concat([labels, test_data, test_data]).drop_duplicates(keep=False)
train_data.head()
# 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()]
# 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)
# checking count of male and females
sns.countplot(labels['Gender']
# 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()