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

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

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

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

Raspberry Pi

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2037閲覧

ラズベリーパイでの画像認識でRuntimeErrorが解決できない

seyu0930

総合スコア20

bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

Raspberry Pi

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

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/06/20 13:36

初めまして。
今日から画像認識について学ぼうと思い、ラズベリーパイ4とカメラモジュールを使ってとりあえず画像認識を体験しようと思いこちらの記事を参考に同じように実行しました。

https://www.souichi.club/raspberrypi/raspicamera-tensorflow/#Coral_USB_Accelerator%E3%82%92%E4%BD%BF%E3%82%8F%E3%81%AA%E3%81%84%E3%81%A7%E5%88%A4%E5%AE%9A

しかし実行する最終段階のところで以下のようなコマンドを打つとエラーが出てしまいました。

bash

1python3 classify_picamera.py \ 2--model /tmp/mobilenet_v1_1.0_224_quant_edgetpu.tflite \ 3--labels /tmp/labels_mobilenet_quant_v1_224.txt

エラー内容

bash

1INFO: Initialized TensorFlow Lite runtime. 2Traceback (most recent call last): 3 File "classify_picamera.py", line 99, in <module> 4 main() 5 File "classify_picamera.py", line 74, in main 6 interpreter.allocate_tensors() 7 File "/home/pi/.local/lib/python3.7/site-packages/tflite_runtime/interpreter.py", line 244, in allocate_tensors 8 return self._interpreter.AllocateTensors() 9 File "/home/pi/.local/lib/python3.7/site-packages/tflite_runtime/interpreter_wrapper.py", line 111, in AllocateTensors 10 return _interpreter_wrapper.InterpreterWrapper_AllocateTensors(self) 11RuntimeError: Encountered unresolved custom op: edgetpu-custom-op.Node number 0 (edgetpu-custom-op) failed to prepare.

この記事と私の環境の違いはおそらくアクセラレーター?というものがついているかどうかだと思います。
edgetpuが関係しているのかなとは思うのですがとりあえず体験してみたいと思って真似してみたので正直どこを直したらいいかわからないです。

回答お待ちしております。よろしくお願いします。

直すべき部分が入っていると思うコード

python

1# python3 2# 3# Copyright 2019 The TensorFlow Authors. All Rights Reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# https://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Example using TF Lite to classify objects with the Raspberry Pi camera.""" 17 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import print_function 21 22import argparse 23import io 24import time 25import numpy as np 26import picamera 27 28from PIL import Image 29from tflite_runtime.interpreter import Interpreter 30 31 32def load_labels(path): 33 with open(path, 'r') as f: 34 return {i: line.strip() for i, line in enumerate(f.readlines())} 35 36 37def set_input_tensor(interpreter, image): 38 tensor_index = interpreter.get_input_details()[0]['index'] 39 input_tensor = interpreter.tensor(tensor_index)()[0] 40 input_tensor[:, :] = image 41 42 43def classify_image(interpreter, image, top_k=1): 44 """Returns a sorted array of classification results.""" 45 set_input_tensor(interpreter, image) 46 interpreter.invoke() 47 output_details = interpreter.get_output_details()[0] 48 output = np.squeeze(interpreter.get_tensor(output_details['index'])) 49 50 # If the model is quantized (uint8 data), then dequantize the results 51 if output_details['dtype'] == np.uint8: 52 scale, zero_point = output_details['quantization'] 53 output = scale * (output - zero_point) 54 55 ordered = np.argpartition(-output, top_k) 56 return [(i, output[i]) for i in ordered[:top_k]] 57 58 59def main(): 60 parser = argparse.ArgumentParser( 61 formatter_class=argparse.ArgumentDefaultsHelpFormatter) 62 parser.add_argument( 63 '--model', help='File path of .tflite file.', required=True) 64 parser.add_argument( 65 '--labels', help='File path of labels file.', required=True) 66 args = parser.parse_args() 67 68 labels = load_labels(args.labels) 69 70 interpreter = Interpreter(args.model) 71 interpreter.allocate_tensors() 72 _, height, width, _ = interpreter.get_input_details()[0]['shape'] 73 74 with picamera.PiCamera(resolution=(640, 480), framerate=30) as camera: 75 camera.start_preview() 76 try: 77 stream = io.BytesIO() 78 for _ in camera.capture_continuous( 79 stream, format='jpeg', use_video_port=True): 80 stream.seek(0) 81 image = Image.open(stream).convert('RGB').resize((width, height), 82 Image.ANTIALIAS) 83 start_time = time.time() 84 results = classify_image(interpreter, image) 85 elapsed_ms = (time.time() - start_time) * 1000 86 label_id, prob = results[0] 87 stream.seek(0) 88 stream.truncate() 89 camera.annotate_text = '%s %.2f\n%.1fms' % (labels[label_id], prob, 90 elapsed_ms) 91 finally: 92 camera.stop_preview() 93 94 95if __name__ == '__main__': 96 main() 97

実行したコマンド

bash

1python3 classify_picamera.py \ 2--model /tmp/mobilenet_v1_1.0_224_quant_edgetpu.tflite \ 3--labels /tmp/labels_mobilenet_quant_v1_224.txt

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

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

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

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

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

jbpb0

2021/06/20 14:27 編集

> この記事と私の環境の違いはおそらくアクセラレーター?というものがついているかどうか ・「mobilenet_v1_1.0_224_quant_edgetpu.tflite」ではなく「mobilenet_v1_1.0_224_quant.tflite」を使う ・参考Webページの「プログラムの修正」に記載の内容(2ヶ所の修正)をやらない (既にやってたら元に戻す) としたら、どうなりますでしょうか?
seyu0930

2021/06/21 00:12

ありがとうございます!おかげさまで無事エラーはなくなりました! INFO: Initialized TensorFlow Lite runtime. ←こちらが出てきたのですがこれは正常でしょうか? ただ、カメラが起動しないのですが、何か自分で起動させるところとかあるのでしょうか。 ラズパイ設定のインターフェースのところのカメラは「有効」にしておりコマンドで写真を撮ることはできる状態です。
seyu0930

2021/06/21 04:17

>>> %Run camera.py というのがshellに表示されてちょうど5秒後に次の >>> が出てくる以外は何も起きないです... そもそもなんですがモニターつけてないとダメだったりしますか? sshでmacから操作していてラズパイ用のモニターはつけてないのですが。
jbpb0

2021/06/21 06:56

私が一つ前のコメントで紹介したWebページの、「注意: カメラのプレビューは...」を読んでください
seyu0930

2021/06/22 07:39

すみません見落としておりました... モニターをつけると録画した動画を見ることはできました。しかし今回のプログラムはうまく実行しません。 2021-06-22 16:30:45.006491: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory Traceback (most recent call last): File "classify_picamera.py", line 96, in <module> main() File "classify_picamera.py", line 70, in main interpreter = Interpreter(args.model) File "/home/pi/.local/lib/python3.7/site-packages/tflite_runtime/interpreter.py", line 206, in __init__ model_path)) NotImplementedError: Wrong number or type of arguments for overloaded function 'InterpreterWrapper_CreateWrapperCPPFromFile'. Possible C/C++ prototypes are: tflite::interpreter_wrapper::InterpreterWrapper::CreateWrapperCPPFromFile(char const *,std::vector< std::string > const &,std::string *) tflite::interpreter_wrapper::InterpreterWrapper::tflite_interpreter_wrapper_InterpreterWrapper_CreateWrapperCPPFromFile__SWIG_1(char const *,PyObject *) こちらのエラーが出たのですが、共有オブジェクトファイルを開くことができません:そのようなファイルまたはディレクトリはありませんとあります。どう考えれば良いでしょうか。何度も申し訳ありません。
seyu0930

2021/06/22 08:05

tensorflowのバージョンが古かったのが原因でした。TFliteとtensorflowを両方入れていたのでこのようなエラーが出ていました。ありがとうございました!
guest

回答1

0

ベストアンサー

この記事と私の環境の違いはおそらくアクセラレーター?というものがついているかどうか

・「mobilenet_v1_1.0_224_quant_edgetpu.tflite」ではなく「mobilenet_v1_1.0_224_quant.tflite」を使う
・参考Webページの「プログラムの修正」に記載の内容(2ヶ所の修正)をやらない (既にやってたら元に戻す)

投稿2021/06/21 12:17

jbpb0

総合スコア7651

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問