有没有一种方法可以获取所有已保存的roi图片的预测?

时间:2019-06-18 11:59:51

标签: opencv3.0 faster-rcnn

我正在尝试加载保存的ROI图像,然后使用mask-rcnn预测图像是什么。但是,当尝试对所有图像运行for循环时,只有第一个图像可以正确预测,然后出现以下错误:

     31   net.setInput(blob)
     32   start = time.time()
---> 33   (boxes, masks) = net.forward(["detection_out_final", "detection_masks"])
     34   end = time.time()
     35 

error: OpenCV(3.4.3) /io/opencv/modules/core/src/matrix.cpp:540: error: (-215:Assertion failed) r == Range::all() || (0 <= r.start && r.start < r.end && r.end <= m.size[i]) in function 'Mat'

代码如下:

images=[]
labelsPath = "CODE/mask-rcnn/mask-rcnn-coco/object_detection_classes_coco.txt"
LABELS = open(labelsPath).read().strip().split("\n")

# load the set of colors that will be used when visualizing a given
# instance segmentation
colorsPath = "CODE/mask-rcnn/mask-rcnn-coco/colors.txt" 
COLORS = open(colorsPath).read().strip().split("\n")
COLORS = [np.array(c.split(",")).astype("int") for c in COLORS]
COLORS = np.array(COLORS, dtype="uint8")

# derive the paths to the Mask R-CNN weights and model configuration
weightsPath = "CODE/mask-rcnn/mask-rcnn-coco/frozen_inference_graph.pb"
configPath = "CODE/mask-rcnn/mask-rcnn-coco/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt"

# load our Mask R-CNN trained on the COCO dataset (90 classes)
# from disk
print("[INFO] loading Mask R-CNN from disk...")
net = cv2.dnn.readNetFromTensorflow(weightsPath, configPath)

# load our input image and grab its spatial dimensions
for i in range(len(int_l)):
  img_name = "roi"+str(i+1)+".png"
  image = cv2.imread(img_name)

  # construct a blob from the input image and then perform a forward
  # pass of the Mask R-CNN, giving us (1) the bounding box  coordinates
  # of the objects in the image along with (2) the pixel-wise segmentation
  # for each specific object
  blob = cv2.dnn.blobFromImage(image, swapRB=True, crop=False)
  net.setInput(blob)
  start = time.time()
  (boxes, masks) = net.forward(["detection_out_final", "detection_masks"])
  end = time.time()

  # show timing information and volume information on Mask R-CNN
  print("[INFO] Mask R-CNN took {:.6f} seconds".format(end - start))
  print("[INFO] boxes shape: {}".format(boxes.shape))
  print("[INFO] masks shape: {}".format(masks.shape))

  for i in range(0, boxes.shape[2]):
    classID = int(boxes[0, 0, i, 1])
    confidence = boxes[0, 0, i, 2]
    print(LABELS[classID]," ",confidence)

是否有一种方法可以依次加载所有保存的ROI图像,然后分别使用mask-rcnn进行预测?任何帮助将不胜感激。

0 个答案:

没有答案