if文を用いて認識した観光地のURLを表示するプログラムの組み方が分かりません。アドバイスお願いします。
栗林公園の公式ホームページにアクセスできるようにしたいです。
python
1import cnn_model 2import keras 3import matplotlib.pyplot as plt 4import numpy as np 5from PIL import Image 6import matplotlib.pyplot as plt 7 8 9im_rows = 32 # 画像の縦ピクセルサイズ 10im_cols = 32 # 画像の横ピクセルサイズ 11im_color = 3 # 画像の色空間 12in_shape = (im_rows, im_cols, im_color) 13nb_classes = 8 14 15LABELS = ["栗林公園", "金刀比羅宮", "瀬戸大橋","丸亀城","伊勢神宮","スカイツリー","レインボーブリッジ","高松城"] 16CALORIES = [588, 118, 648] 17 18# 保存したCNNモデルを読み込む 19model = cnn_model.get_model(in_shape, nb_classes) 20model.load_weights('./image/photos-model.hdf5') 21 22def check_photo(path): 23 # 画像を読み込む 24 img = Image.open(path) 25 img = img.convert("RGB") # 色空間をRGBに 26 img = img.resize((im_cols, im_rows)) # サイズ変更 27 plt.imshow(img) 28 plt.show() 29 # データに変換 30 x = np.asarray(img) 31 x = x.reshape(-1, im_rows, im_cols, im_color) 32 x = x / 255 33 34 # 予測 35 pre = model.predict([x])[0] 36 idx = pre.argmax() 37 per = int(pre[idx] * 100) 38 return (idx, per) 39 40def check_photo_str(path): 41 idx, per = check_photo(path) 42 # 答えを表示 43 print("この写真は、", LABELS[idx]) 44 print("可能性は、", per, "%") 45 46 47 #保存してある写真データからテストを行う 48if __name__ == '__main__': 49 check_photo_str('riturin.jpg') 50 check_photo_str('kkk.jpg') 51 check_photo_str('brige.jpg') 52 check_photo_str('setooohasi.jpg') 53 check_photo_str('SetoBridge1.jpg')
補足情報
python3.6.6
mac OS Mojava
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。