Skip to content

Image recognition (Face/object), part2

On the previous post we had discussed on the notion of installing a python lib to be used to match faces from a known directory of images. This time, we will be working with identifying images as physical objects with a predefined known DB file rather than matching faces.

We have to install quite a few python libraries this time around in order to start matching objects in an given image with a database of predefined items.

pip3 install --user tensorflow
pip3 install --user numpy
pip3 install --user scipy
pip3 install --user opencv-python
pip3 install --user matplotlib
pip3 install --user h5py
pip3 install --user keras
pip3 install --user imageai
wget https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels.h5

I've downloaded this particular 100MB file to the Download directory and pulled an arbitary banana image file as my test into a /var/tmp directory location.


#!/usr/bin/env python3
# Sample Image Prediction with AI and Tensorflow
# imgPrediction.py
################################################

from imageai.Prediction import ImagePrediction
import os

execution_path = os.getcwd()
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath( execution_path + "/Downloads/resnet50_weights_tf_dim_ordering_tf_kernels.h5")
prediction.loadModel()


predictions, percentage_probabilities = prediction.predictImage("/var/tmp/Bananas.jpg", result_count=5)

for index in range(len(predictions)):
    print(predictions[index] , " : " , percentage_probabilities[index])
# results are as follows

 hobbit@Hobbit : ~ $ python3 imgPrediction.py
2020-02-03 22:30:42.018504: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-02-03 22:30:42.063861: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fad5b33bbf0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-02-03 22:30:42.063890: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
banana  :  98.45277667045593
lemon  :  0.7330755237489939
orange  :  0.5388087593019009
zucchini  :  0.07304142927750945
acorn_squash  :  0.052256841445341706

There is something with tensorflow where this CPU cant seem to run, apparently. Ignore those two warning messages and read the bottom 6 lines. Its comical that using this AI image library, it was able to identify this banana.jpg file with pretty high accuracy. again, i did the opposite with this software to match to see if this application would know a person's name or title by reading a jpg file with a facial image. After using one of the images from the previous post, it was able to identify a tie and a suit with 95% certainly but not the person's name nor their title. 

In term of facial recognition, image object AI when using a predefined DB has its own limitations when trying to ID a face. There doesnt seem to be a software, which can do both: facial recognition and ID-ing objects. 

You can find the step by step writeup with explainations from this author:
View at Medium.com

Leave a Reply

Your email address will not be published.