# draw a rectangle on the image
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (255, 255, 255), 2)
for file in pathlib.Path('/content/gdrive/MyDrive/ACAD/SEM 7/PROJECT/covertingTF/test_images/').iterdir():
if file.suffix != '.jpg' and file.suffix != '.png':
continue
img = cv2.imread(r"{}".format(file.resolve()))
from google.colab.patches import cv2_imshow
new_img = cv2.resize(img, (416, 416))
interpreter.set_tensor(input_details[0]['index'], [new_img])
interpreter.invoke()
rects = interpreter.get_tensor(
output_details[0]['index'])
scores = interpreter.get_tensor(
output_details[2]['index'])
for index, score in enumerate(scores[0]):
if score > 0.5:
draw_rect(new_img,rects[0][index])
cv2.imshow("image", new_img)
cv2.waitKey(0)
ERROR--
IndexError Traceback (most recent call last)
in ()
38
39 scores = interpreter.get_tensor(
---> 40 output_details[2]['index'])
41
42 for index, score in enumerate(scores[0]):
IndexError: list index out of range
I managed to convert .pb file of Faster RCNN to .tflite. But while testing the detection code it gives " list index out of range" error
CODE -
import tensorflow as tf import numpy as np import cv2 import pathlib
interpreter = tf.lite.Interpreter(model_path="/content/gdrive/MyDrive/ACAD/SEM 7/PROJECT/covertingTF/detect4.tflite")
input_details = interpreter.get_input_details() output_details = interpreter.get_output_details()
print(input_details) print(output_details)
interpreter.allocate_tensors() print(['index']) def draw_rect(image, box): y_min = int(max(1, (box[0] image.height))) x_min = int(max(1, (box[1] image.width))) y_max = int(min(image.height, (box[2] image.height))) x_max = int(min(image.width, (box[3] image.width)))
for file in pathlib.Path('/content/gdrive/MyDrive/ACAD/SEM 7/PROJECT/covertingTF/test_images/').iterdir():
ERROR--
IndexError Traceback (most recent call last)