Flickrから画像をダウンロードしたのですが
サラダと豆腐はチャンと300枚フォルダーに保存出来てましたが
寿司の画像がたったの4枚だけ
仕方なく、フリー素材からダウンロードすることにしました
下が最後のカロリー判定のコードと結果です
import cnn_model
import keras
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import keras
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
target_image = "test-sushi.jpg"
im_rows = 64 # 画像の縦ピクセルサイズ
im_cols = 64 # 画像の横ピクセルサイズ
im_color = 3 # 画像の色空間
in_shape = (im_rows, im_cols, im_color)
nb_classes = 3
im_cols = 64 # 画像の横ピクセルサイズ
im_color = 3 # 画像の色空間
in_shape = (im_rows, im_cols, im_color)
nb_classes = 3
LABELS = ["寿司", "サラダ", "麻婆豆腐"]
CALORIES = [588, 118, 648] # 結構適当です.決め打ち
CALORIES = [588, 118, 648] # 結構適当です.決め打ち
# 保存したCNNモデルを読み込む
model = cnn_model.get_model(in_shape, nb_classes)
model.load_weights('./image/photos-model.hdf5')
model = cnn_model.get_model(in_shape, nb_classes)
model.load_weights('./image/photos-model.hdf5')
def check_photo(path):
# 画像を読み込む
img = Image.open(path)
img = img.convert("RGB") # 色空間をRGBに
img = img.resize((im_cols, im_rows)) # サイズ変更
plt.xticks(color="None")
plt.yticks(color="None")
plt.tick_params(length=0)
plt.imshow(img)
plt.show()
# データに変換
x = np.asarray(img)
x = x.reshape(-1, im_rows, im_cols, im_color)
x = x / 255
# 画像を読み込む
img = Image.open(path)
img = img.convert("RGB") # 色空間をRGBに
img = img.resize((im_cols, im_rows)) # サイズ変更
plt.xticks(color="None")
plt.yticks(color="None")
plt.tick_params(length=0)
plt.imshow(img)
plt.show()
# データに変換
x = np.asarray(img)
x = x.reshape(-1, im_rows, im_cols, im_color)
x = x / 255
# 予測
pre = model.predict([x])[0]
idx = pre.argmax()
per = int(pre[idx] * 100)
return (idx, per)
pre = model.predict([x])[0]
idx = pre.argmax()
per = int(pre[idx] * 100)
return (idx, per)
def check_photo_str(path):
idx, per = check_photo(path)
# 答えを表示
print("この写真は、", LABELS[idx], "で、カロリーは", CALORIES[idx],"kcal")
print("可能性は、", per, "%")
idx, per = check_photo(path)
# 答えを表示
print("この写真は、", LABELS[idx], "で、カロリーは", CALORIES[idx],"kcal")
print("可能性は、", per, "%")
if __name__ == '__main__':
check_photo_str('test-sushi.jpg')
check_photo_str('test-salad.jpg')
check_photo_str('test-sushi.jpg')
check_photo_str('test-salad.jpg')