Unable to Loop the Inference of a Model That Has 2 Outputs
Content Type: Troubleshooting | Article ID: 000092895 | Last Reviewed: 06/16/2023
Unable to handle a model that has 2 outputs when using the function code below:
for i, detection in enumerate(detections):
#_, image_id, confidence, xmin, ymin, xmax, ymax = detection
xmin, ymin, xmax, ymax, confidence = detection
if confidence > 0.2:
xmin = int(max((xmin * image.shape[1]), 10))
ymin = int(max((ymin * image.shape[0]), 10))
xmax = int(min((xmax * image.shape[1]), image.shape[1] - 10))
ymax = int(min((ymax * image.shape[0]), image.shape[0] - 10))
To enable the looping of 2 model outputs, take both outputs into account because output2 may contain a background class.
Reuse the part of the code as below:
# output1, output2 = model()
for i, (detection, label) in enumerate(zip(output1, output2)): #_, image_id, confidence, xmin, ymin, xmax, ymax = detection xmin, ymin, xmax, ymax, confidence = detection if confidence > 0.2 and label == 1: # reuse the code from the example