Я пытаюсь загрузить сохраненные изображения ROI и затем использовать mask-rcnn, чтобы предсказать, что это за изображение.Но при попытке запустить цикл for со всеми изображениями правильно прогнозируется только 1-е изображение, а затем выдается следующая ошибка:
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 для их прогнозирования соответственно?Любая помощь будет оценена.