[PYTHON] I tried image recognition of CIFAR-10 with Keras-Image recognition-

Introduction

-Last time, I tried image recognition based on the learned model. ――The accuracy seems to be good.

Forecasting program

#!/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])

Prediction result

――I did it with the following 5 sheets.

Ferrari

1.jpg

automobile

Miniature Dachshund

2.jpg

frog

Cat

3.jpg

hourse

Large cruise ship

4.jpg

ship

deep Impact

5.jpg

hourse

Impressions

-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

I tried image recognition of CIFAR-10 with Keras-Image recognition-
I tried image recognition of CIFAR-10 with Keras-Learning-
I tried simple image recognition with Jupyter
I tried handwriting recognition of runes with scikit-learn
[OpenCV / Python] I tried image analysis of cells with OpenCV
I tried face recognition with OpenCV
I tried to find the entropy of the image with python
I tried handwriting recognition of runes with CNN using Keras
I tried playing with the image with Pillow
I tried "smoothing" the image with Python + OpenCV
I tried hundreds of millions of SQLite with python
I tried "differentiating" the image with Python + OpenCV
Image recognition with keras
I tried Flask with Remote-Containers of VS Code
I tried to correct the keystone of the image
I tried "binarizing" the image with Python + OpenCV
I tried using the image filter of OpenCV
I tried simple image processing with Google Colaboratory.
I tried to make a simple image recognition API with Fast API and Tensorflow
I tried to extract features with SIFT of OpenCV
[Introduction to Pytorch] I tried categorizing Cifar10 with VGG16 ♬
I tried "morphology conversion" of images with Python + OpenCV
I tried fp-growth with python
I tried scraping with Python
[PyTorch] Image classification of CIFAR-10
I tried AutoGluon's Image Classification
I tried Learning-to-Rank with Elasticsearch!
I tried face recognition using Face ++
I tried clustering with PyCaret
Application of CNN2 image recognition
I tried image recognition of "Moon and Soft-shelled Turtle" with Pytorch (using torchvision.datasets.ImageFolder which corresponds to from_from_directry of keras)
I tried gRPC with Python
I tried scraping with python
Image recognition with Keras + OpenCV
Image processing with Python (I tried binarizing it into a mosaic art of 0 and 1)
I tried to find the average of the sequence with TensorFlow
I tried starting Django's server with VScode instead of Pycharm
I tried running Movidius NCS with python of Raspberry Pi3
I tried face recognition of the laughter problem using Keras.
I tried to implement ListNet of rank learning with Chainer
I tried a stochastic simulation of a bingo game with Python
I tried trimming efficiently with OpenCV
I tried summarizing sentences with summpy
seam carving (image cropping) I tried
I tried machine learning with liblinear
I tried web scraping with python.
I tried knocking 100 image processes (Q1 ~ Q10)
I tried moving food with SinGAN
I tried using GrabCut of OpenCV
I tried implementing DeepPose with PyTorch
I tried face detection with MTCNN
I tried running prolog with python 3.8.2.
Image recognition of fruits using VGG16
I tried SMTP communication with Python
I tried sentence generation with GPT-2
I tried learning LightGBM with Yellowbrick
I tried scraping the ranking of Qiita Advent Calendar with Python
I tried to automate the watering of the planter with Raspberry Pi
I tried to build the SD boot image of LicheePi Nano
I tried to create a list of prime numbers with python
I tried to process the image in "sketch style" with OpenCV