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

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

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

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

Q&A

0回答

194閲覧

TensorFlowのObject Detection(物体検知) のデモが動かない

JjJj9

総合スコア10

Python

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

0グッド

0クリップ

投稿2019/04/12 06:42

編集2022/01/12 10:55

前提・実現したいこと

TensorFlowのObject Detection(物体検知) のサンプルプログラムを改良して
最終的には、用意したデータセットに人が含まれているかどうかを分類したいです

サンプルのGitHubはこちらです
https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb

このサンプルではローカルにおいた画像に対して処理をしているのですが、
最初の改変として
AWSのS3においてある画像を読み込んで、それに対いて物体検知の処理をするようにしたいです

発生している問題・エラーメッセージ

ValueError Traceback (most recent call last) <ipython-input-11-6c071478012d> in <module> 115 # Actual detection. 116 --> 117 output_dict = run_inference_for_single_image(img_list, detection_graph) 118 #output_dict = run_inference_for_single_image(image_np_expanded, detection_graph) 119 # Visualization of the results of a detection. <ipython-input-11-6c071478012d> in run_inference_for_single_image(image, graph) 54 # Run inference 55 output_dict = sess.run(tensor_dict, ---> 56 feed_dict={image_tensor: image}) 57 58 # all outputs are float32 numpy arrays, so convert types as appropriate ~\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata) 927 try: 928 result = self._run(None, fetches, feed_dict, options_ptr, --> 929 run_metadata_ptr) 930 if run_metadata: 931 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) ~\Anaconda3\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 1126 'which has shape %r' % 1127 (np_val.shape, subfeed_t.name, -> 1128 str(subfeed_t.get_shape()))) 1129 if not self.graph.is_feedable(subfeed_t): 1130 raise ValueError('Tensor %s may not be fed.' % subfeed_t) ValueError: Cannot feed value of shape (0,) for Tensor 'image_tensor:0', which has shape '(?, ?, ?, 3)'

該当のソースコード

# 画像の準備 for flg in [0,1]: # データディレクトリの定義 if flg == 0: d_dir = DATA_LOCATION_FLG0 elif flg == 1: d_dir = DATA_LOCATION_FLG1 s3 = boto3.resource('s3') bucket = s3.Bucket(BUCKET_NAME) s3client = boto3.Session().client('s3') response = s3client.list_objects( Bucket=BUCKET_NAME, Prefix='%s/'%(d_dir) ) # 該当する key がないと response に 'Contents' が含まれない if 'Contents' in response: keys = [content['Key'] for content in response['Contents']] # ディレクトリ名を消す del keys[0] st = time.time() img_list = [] for i in range(len(keys)//MINI_BATCH): img_list = get_imgs(bucket,keys,st=i*MINI_BATCH,le=MINI_BATCH) print(img_list) #img = resize(img_list, (224, 224)) output_dict = run_inference_for_single_image(img_list, detection_graph) # Visualization of the results of a detection. vis_util.visualize_boxes_and_labels_on_image_array( image_np, output_dict['detection_boxes'], output_dict['detection_classes'], output_dict['detection_scores'], category_index, instance_masks=output_dict.get('detection_masks'), use_normalized_coordinates=True, line_thickness=8) plt.figure(figsize=IMAGE_SIZE) plt.imshow(image_np)

試したこと

・keyをprint して値が入っていることを確認しています

補足情報(FW/ツールのバージョンなど)

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問