前提・実現したいこと
Raspberry Pi上で物体検出を行いたいです。
cnnを構築し、model.predict()を実行した際に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
パスエラー
python
1import cv2 2import keras 3from keras.applications.imagenet_utils import preprocess_input 4from keras.backend.tensorflow_backend import set_session 5from keras.models import Model 6from keras.preprocessing import image 7import matplotlib.pyplot as plt 8import numpy as np 9from scipy.misc import imread 10import tensorflow as tf 11 12from ssd import SSD300 13 14from ssd_utils import BBoxUtility 15 16#%matplotlib inline 17plt.rcParams['figure.figsize'] = (8, 8) 18plt.rcParams['image.interpolation'] = 'nearest' 19 20np.set_printoptions(suppress=True) 21 22#config = tf.ConfigProto() 23#config.gpu_options.per_process_gpu_memory_fraction = 0.9 24#set_session(tf.Session(config=config)) 25 26voc_classes = ['Aeroplane', 'Bicycle', 'Bird', 'Boat', 'Bottle', 27 'Bus', 'Car', 'Cat', 'Chair', 'Cow', 'Diningtable', 28 'Dog', 'Horse','Motorbike', 'Person', 'Pottedplant', 29 'Sheep', 'Sofa', 'Train', 'Tvmonitor'] 30NUM_CLASSES = len(voc_classes) + 1 31 32input_shape=(300, 300, 3) 33model = SSD300(input_shape, num_classes=NUM_CLASSES) 34 35model.load_weights('weights_SSD300.hdf5', by_name=True) 36bbox_util = BBoxUtility(NUM_CLASSES) 37 38inputs = [] 39images = [] 40img_path = './1.jpg' 41img = image.load_img(img_path, target_size=(300, 300)) 42img = image.img_to_array(img) 43images.append(imread(img_path)) 44inputs.append(img.copy()) 45inputs = preprocess_input(np.array(inputs)) 46 47preds = model.predict(inputs, batch_size=1, verbose=1) 48 49results = bbox_util.detection_out(preds) 50 51#%%time 52a = model.predict(inputs, batch_size=1) 53b = bbox_util.detection_out(preds) 54for i, img in enumerate(images): 55 # Parse the outputs. 56 det_label = results[i][:, 0] 57 det_conf = results[i][:, 1] 58 det_xmin = results[i][:, 2] 59 det_ymin = results[i][:, 3] 60 det_xmax = results[i][:, 4] 61 det_ymax = results[i][:, 5] 62 63 # Get detections with confidence higher than 0.6. 64 top_indices = [i for i, conf in enumerate(det_conf) if conf >= 0.6] 65 66 top_conf = det_conf[top_indices] 67 top_label_indices = det_label[top_indices].tolist() 68 top_xmin = det_xmin[top_indices] 69 top_ymin = det_ymin[top_indices] 70 top_xmax = det_xmax[top_indices] 71 top_ymax = det_ymax[top_indices] 72 73 colors = plt.cm.hsv(np.linspace(0, 1, 21)).tolist() 74 75 plt.imshow(img / 255.) 76 currentAxis = plt.gca() 77 78 for i in range(top_conf.shape[0]): 79 xmin = int(round(top_xmin[i] * img.shape[1])) 80 ymin = int(round(top_ymin[i] * img.shape[0])) 81 xmax = int(round(top_xmax[i] * img.shape[1])) 82 ymax = int(round(top_ymax[i] * img.shape[0])) 83 score = top_conf[i] 84 label = int(top_label_indices[i]) 85 label_name = voc_classes[label - 1] 86 display_txt = '{:0.2f}, {}'.format(score, label_name) 87 coords = (xmin, ymin), xmax-xmin+1, ymax-ymin+1 88 color = colors[label] 89 currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2)) 90 currentAxis.text(xmin, ymin, display_txt, bbox={'facecolor':color, 'alpha':0.5}) 91 92 plt.show() 93
試したこと
補足に示す環境で別のPC上で実行しましたが、エラーは返されませんでした。
エラーメッセージを検索しましたが、同様の例が見られませんでしたので、質問させていただきました。
補足情報
python=3.5.3
Tensorflow=1.11.0
Keras=2.2.4
model.predict()でエラーが返されることは
ソースコードをコメントアウトしながら調べました。
エラーは”パスエラー”で全文です。
https://github.com/rykov8/ssd_keras?files=1
上記のコードを
https://qiita.com/ttskng/items/4f67f4bbda2568229956
に従って変更し、
SSD.ipynbの各セルをテキストファイルにコピーペーストしてSSD.pyとし、実行しました。
上記のコードがSSD.pyです。
画像はSSD.pyと同じディレクトリに置いています。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー