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

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

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

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python 2.7

Python 2.7は2.xシリーズでは最後のメジャーバージョンです。Python3.1にある機能の多くが含まれています。

Python

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

Q&A

解決済

1回答

2252閲覧

pycaffe関連のエラー:Exception: Input blob arguments do not match net inputs.

R_12.Kunc

総合スコア14

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python 2.7

Python 2.7は2.xシリーズでは最後のメジャーバージョンです。Python3.1にある機能の多くが含まれています。

Python

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

0グッド

0クリップ

投稿2016/10/13 09:11

ここを参考に,caffemodelを自分用に適用してウェブカメラ映像からリアルタイムで人を検出しようとしています.

このスクリプトを実行したところ,このようなエラーが出てきました.

Traceback (most recent call last): File "realtime2.py", line 150, in <module> [im2, cls, dets, CONF_THRESH] = demo(net, frame, scale_factor, ('person',)) File "realtime2.py", line 87, in demo scores, boxes = im_detect(net, im2, obj_proposals) File "/home/keisan/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 154, in im_detect blobs_out = net.forward(**forward_kwargs) File "/home/keisan/py-faster-rcnn/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 97, in _Net_forward raise Exception('Input blob arguments do not match net inputs.') Exception: Input blob arguments do not match net inputs.

このエラーの意味はどういった内容なのでしょうか?(ググってもいまいちピンときません)
また,どのような対処法が考えられるでしょうか?
どなたかご教示よろしくお願いします.

私のスクリプトは以下のとおりです

python

1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# -------------------------------------------------------- 5# Fast R-CNN 6# Copyright (c) 2015 Microsoft 7# Licensed under The MIT License [see LICENSE for details] 8# Written by Ross Girshick 9# -------------------------------------------------------- 10 11""" 12Demo script showing detections in sample images. 13See README.md for installation instructions before running. 14""" 15 16import _init_paths 17from fast_rcnn.config import cfg 18from fast_rcnn.test import im_detect 19from fast_rcnn.nms_wrapper import nms 20from utils.timer import Timer 21import matplotlib.pyplot as plt 22import numpy as np 23import scipy.io as sio 24import caffe, os, cv2 25import argparse 26import dlib 27 28CLASSES = ('__background__', 29 'aeroplane', 'bicycle', 'bird', 'boat', 30 'bottle', 'bus', 'car', 'cat', 'chair', 31 'cow', 'diningtable', 'dog', 'horse', 32 'motorbike', 'person', 'pottedplant', 33 'sheep', 'sofa', 'train', 'tvmonitor') 34 35NETS = {'vgg16': ('VGG16', 36 'VGG16_faster_rcnn_final.caffemodel'), 37 'zf': ('ZF', 38 'ZF_faster_rcnn_final.caffemodel')} 39 40 41def vis_detections(im, class_name, dets, thresh=0.5): 42 """Draw detected bounding boxes.""" 43 inds = np.where(dets[:, -1] >= thresh)[0] 44 if len(inds) == 0: 45 return 46 47 im = im[:, :, (2, 1, 0)] 48 fig, ax = plt.subplots(figsize=(12, 12)) 49 ax.imshow(im, aspect='equal') 50 for i in inds: 51 bbox = dets[i, :4] 52 score = dets[i, -1] 53 54 ax.add_patch( 55 plt.Rectangle((bbox[0], bbox[1]), 56 bbox[2] - bbox[0], 57 bbox[3] - bbox[1], fill=False, 58 edgecolor='red', linewidth=3.5) 59 ) 60 ax.text(bbox[0], bbox[1] - 2, 61 '{:s} {:.3f}'.format(class_name, score), 62 bbox=dict(facecolor='blue', alpha=0.5), 63 fontsize=14, color='white') 64 65 ax.set_title(('{} detections with ' 66 'p({} | box) >= {:.1f}').format(class_name, class_name, 67 thresh), 68 fontsize=14) 69 plt.axis('off') 70 plt.tight_layout() 71 plt.draw() 72 73def demo(net, im, scale_factor, classes): 74 """Detect object classes in an image using pre-computed object proposals.""" 75 76 im2 = cv2.resize(im, (0,0), fx=1.0/scale_factor, fy=1.0/scale_factor) 77 78 obj_proposals_in = [] 79 dlib.find_candidate_object_locations(im2, obj_proposals_in, min_size=70) 80 81 obj_proposals = np.empty((len(obj_proposals_in),4)) 82 for idx in range(len(obj_proposals_in)): 83 obj_proposals[idx] = [obj_proposals_in[idx].left(), obj_proposals_in[idx].top(), obj_proposals_in[idx].right(), obj_proposals_in[idx].bottom()] 84 85 # Detect all object classes and regress object bounds 86 scores, boxes = im_detect(net, im2, obj_proposals) 87 88 # Visualize detections for each class 89 CONF_THRESH = 0.8 90 NMS_THRESH = 0.3 91 for cls in classes: 92 cls_ind = CLASSES.index(cls) 93 cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)] 94 cls_scores = scores[:, cls_ind] 95 dets = np.hstack((cls_boxes, 96 cls_scores[:, np.newaxis])).astype(np.float32) 97 keep = nms(dets, NMS_THRESH) 98 dets = dets[keep, :] 99 100 return [im2, cls, dets, CONF_THRESH] 101 102 103def parse_args(): 104 """Parse input arguments.""" 105 parser = argparse.ArgumentParser(description='Train a Fast R-CNN network') 106 parser.add_argument('--gpu', dest='gpu_id', help='GPU device id to use [0]', 107 default=0, type=int) 108 parser.add_argument('--cpu', dest='cpu_mode', 109 help='Use CPU mode (overrides --gpu)', 110 action='store_true') 111 parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16]', 112 choices=NETS.keys(), default='vgg16') 113 114 args = parser.parse_args() 115 116 return args 117 118 119if __name__ == '__main__': 120 args = parse_args() 121 122 prototxt = os.path.join(cfg.MODELS_DIR, NETS[args.demo_net][0], 123 'faster_rcnn_alt_opt', 'faster_rcnn_test.pt') 124 caffemodel = os.path.join(cfg.DATA_DIR, 'faster_rcnn_models', 125 NETS[args.demo_net][1]) 126 127 if not os.path.isfile(caffemodel): 128 raise IOError(('{:s} not found.\nDid you run ./data/script/' 129 'fetch_fast_rcnn_models.sh?').format(caffemodel)) 130 131 if args.cpu_mode: 132 caffe.set_mode_cpu() 133 else: 134 caffe.set_mode_gpu() 135 caffe.set_device(args.gpu_id) 136 net = caffe.Net(prototxt, caffemodel, caffe.TEST) 137 138 print '\n\nLoaded network {:s}'.format(caffemodel) 139 140 cap = cv2.VideoCapture(0) 141 142 while(True): 143 # Capture frame-by-frame 144 ret, frame = cap.read() 145 146 # Scaling the video feed can help the system run faster (and run on GPUs with less memory) 147 # e.g. with a standard video stream of size 640x480, a scale_factor = 4 will allow the system to run a < 1 sec/frame 148 scale_factor = 4 149 [im2, cls, dets, CONF_THRESH] = demo(net, frame, scale_factor, ('person',)) 150 151 inds = np.where(dets[:, -1] >= CONF_THRESH)[0] 152 if len(inds) != 0: 153 for i in inds: 154 bbox = dets[i, :4] 155 cv2.rectangle(frame,(int(bbox[0]*scale_factor),int(bbox[1]*scale_factor)),(int(bbox[2]*scale_factor),int(bbox[3]*scale_factor)),(0,255,0),2) 156 157 # Display the resulting frame 158 cv2.imshow('frame',frame) 159 160 if cv2.waitKey(1) & 0xFF == ord('q'): 161 break 162 163 # When everything done, release the capture 164 cap.release() 165cv2.destroyAllWindows()

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

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

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

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

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

guest

回答1

0

自己解決

py-faster-rcnnのissueで同じ問題が公開されていました

投稿2017/01/25 05:09

R_12.Kunc

総合スコア14

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問