Simple image classification on raspberry pi using the pre-trained model VGG16 and TensorFlow
Short summary:
In this article, I will explain, how to create simple image classification on raspberry pi using the pre-trained model VGG16. All code is located here.
Note before you start:
So, Let’s start :)
Hardware preparation:
Software preparation:
1 Create file image_classify.py with next code:
In this example, I will use the pre-train model VGG16, but you can try to use any pre-train model.
#import modules
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input, decode_predictions
import numpy as np#load imgenet vgg16 model
model = VGG16(weights='imagenet')#load image and change size to 224*224
img_path = 'demo.jpg'
img = image.load_img(img_path, target_size=(224, 224))#convert image to array
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)#predict class for image
preds = model.predict(x)
print('Result:', decode_predictions(preds, top=1)[0])
2 run script for recognizing the image
python3 image_classify.py
3 You should see something like that
And this result absolutely right :)
Result:
In this article, we created simple image classification on raspberry pi using the pre-trained model VGG16. All code is located here.