質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Q&A

解決済

1回答

777閲覧

Raspberry Pi、Kerasでパスエラー

mmiko

総合スコア13

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

0グッド

0クリップ

投稿2019/01/07 09:34

編集2019/01/08 00:26

前提・実現したいこと

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と同じディレクトリに置いています。

よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hayataka2049

2019/01/07 11:29

エラーはそれで全文でしょうか。出たものは省略せずすべて掲載してください。質問は再編集できます。
mmiko

2019/01/07 11:46

コメントありがとうございます。 紛らわしく申し訳ありません。 “パスエラー”が全文となります。
hayataka2049

2019/01/07 11:50

ソースコード全文を貼るか、もし他サイト等からコピペして動かしているならそこにリンクしてください
hayataka2049

2019/01/07 12:19

「パスエラー」だけ出てくるというのは一般的なエラーメッセージではない気がするので、実行しているコードが直接吐いているメッセージかもしれません。だとするとコードがわからない限りどうにもなりません
guest

回答1

0

ベストアンサー

tanakataさん、

こちらで確認したところ、通常のpip install tensorflowでインストールしたものでは、Bus Error と表示されました。

https://github.com/tensorflow/tensorflow/issues/15062#issuecomment-435890116 のコメントの、PINTO0309さんがNative buildしたものに差し替えてみたら、Bus Errorは、発生しませんでした。
確認してみてください。

# PINTO0309さんのバイナリ取得 wget https://github.com/PINTO0309/Tensorflow-bin/raw/master/tensorflow-1.11.0-cp35-cp35m-linux_armv7l.whl # 現在のTensorflowをアンインストール pip uninstall tensorflow # ダウンロードしてきたのをインストール pip install ./tensorflow-1.11.0-cp35-cp35m-linux_armv7l.whl

環境に応じて、sudoをつけたり、してみてください。

環境

  • Raspberry Pi 3B+
  • Raspbian: 2018-11-13-raspbian-stretch
  • Python 3.5.3(Raspbian付属) + virtualenv にて、環境作成
  • Tensorflow==1.11.0 (※2種類)
  • keras==2.2.4
  • opencv-python-headless==3.4.4

投稿2019/01/08 06:24

mt08

総合スコア1825

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mmiko

2019/01/08 06:53

動作が確認できました! ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問