#!/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__':
# モデルを読み込む
model_json = open('model.json').read()
model = model_from_json(model_json)
model.load_weights('model.h5')
# 画像を読み込む
image = load_img('{画像ファイルパス}', target_size=(32, 32))
# 配列に変換
x = img_to_array(image)
# 次元数を増やす
x = np.expand_dims(x, axis=0)
# 入力データは[0,1]の範囲に正規化
x = x.astype('float32')
x /= 255.0
# 予測
preds = model.predict(x)
# 最大値のインデックスを取得
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])