"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

March 31, 2017

Day #59 - Image Object Classification using Keras

This post is for basic image classification in Keras using VGG19. We leverage pre-trained models to detect objects in the image


from keras.applications import VGG19
from keras.applications import imagenet_utils
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
import numpy as np
input_shape = (224,224)
preprocess = imagenet_utils.preprocess_input
image = load_img("E:\RNotes\DL\man.png", target_size = input_shape)
image = img_to_array(image)
image = np.expand_dims(image,axis=0)
image = preprocess(image)
#model = VGG19(weights="imagenet")
model = VGG19(weights="imagenet")
preds = model.predict(image)
p = imagenet_utils.decode_predictions(preds)
print(p)
#VGG19
#Women
#[[('n03770439', 'miniskirt', 0.47218892), ('n03594734', 'jean', 0.20757468), ('n02963159', 'cardigan', 0.022973826), ('n03450230', 'gown', 0.021934472), ('n03000247', 'chain_mail', 0.02097792)]]
#man
#[[('n03594734', 'jean', 0.31298622), ('n03630383', 'lab_coat', 0.26774961), ('n04456115', 'torch', 0.083450332), ('n04296562', 'stage', 0.04125011), ('n04370456', 'sweatshirt', 0.021016017)]]
Happy Learning!!!

No comments: