Experiment #1 - Used the existing model and took faces from edouardjanssens.com for both men / women from 1-100 in increments of 5. The actual result and predicted chart summary
Demo Code
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
#http://edouardjanssens.com/art/1-to-100-years/men/ | |
#http://edouardjanssens.com/art/1-to-100-years/women/ | |
import cv2 | |
print(cv2.__version__) | |
import glob, os | |
from pyagender import PyAgender | |
agender = PyAgender() | |
def Approach1(): | |
f = open(r'C:\Data_ML\Data_Scrub\Results.csv','w') | |
os.chdir(r"C:\Data_ML\Data_Scrub\Boys") | |
for file in glob.glob("*.*"): | |
faces = agender.detect_genders_ages(cv2.imread(file)) | |
#print(faces) | |
print("_________________________________________________") | |
print(file) | |
for data in faces: | |
for key in data: | |
if(key=='gender' or key == 'age'): | |
if key=='gender': | |
if data[key] <0.5: | |
print(key) | |
print('Male') | |
val1 = 'Male' | |
else: | |
print(key) | |
print('Female') | |
val1 = 'Female' | |
if key=='age': | |
print(key) | |
print(data[key]) | |
val2= data[key] | |
print("_________________________________________________") | |
data = file + "," + str(val1) + "," + str(val2) + "\n" | |
f.write(data) | |
f.close() | |
Few tweaks in code
Demo Code
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
#https://github.com/divamgupta/image-segmentation-keras | |
import keras_segmentation | |
model = keras_segmentation.pretrained.pspnet_50_ADE_20K() # load the pretrained model trained on ADE20k dataset | |
# load 3 pretrained models | |
out = model.predict_segmentation( | |
inp=r"E:\Code_Repo\image-segmentation-keras\sample_images\Data1.jpeg", | |
out_fname=r"E:\Code_Repo\image-segmentation-keras\sample_images\out1.png" | |
) | |
model2 = keras_segmentation.pretrained.pspnet_101_cityscapes() | |
out = model2.predict_segmentation( | |
inp=r"E:\Code_Repo\image-segmentation-keras\sample_images\Data1.jpeg", | |
out_fname=r"E:\Code_Repo\image-segmentation-keras\sample_images\out2.png" | |
) | |
model3 = keras_segmentation.pretrained.pspnet_101_voc12() | |
out = model3.predict_segmentation( | |
inp=r"E:\Code_Repo\image-segmentation-keras\sample_images\Data1.jpeg", | |
out_fname=r"E:\Code_Repo\image-segmentation-keras\sample_images\out3.png" | |
) | |
No comments:
Post a Comment