-Last time, I tried image recognition based on the learned model. ――The accuracy seems to be good.
#!/usr/local/bin/python3
#!-*- coding: utf-8 -*-
import os
import numpy as np
from keras.models import model_from_json
from keras.preprocessing.image import load_img, img_to_array
if __name__ == '__main__':
#Load the model
model_json = open('model.json').read()
model = model_from_json(model_json)
model.load_weights('model.h5')
#Load image
image = load_img('{Image file path}', target_size=(32, 32))
#Convert to an array
x = img_to_array(image)
#Increase the number of dimensions
x = np.expand_dims(x, axis=0)
#Input data is[0,1]Normalize to the range of
x = x.astype('float32')
x /= 255.0
#Forecast
preds = model.predict(x)
#Get index of maximum value
answer = np.argmax(preds)
cifar_map = {
0: "airplane",
1: "automobile",
2: "bird",
3: "cat",
4: "deer",
5: "dog",
6: "frog",
7: "hourse",
8: "ship",
9: "truck"
}
print(cifar_map[answer])
――I did it with the following 5 sheets.
automobile
frog
hourse
ship
hourse
-Is it difficult to understand because quadrupedal animals have similar features? ――If you process the image to make it more noticeable, the accuracy may improve a little.
Recommended Posts