@@ -150,6 +150,15 @@ def stop(self):
150
150
input_mean = 127.5
151
151
input_std = 127.5
152
152
153
+ # Check output layer name to determine if this model was created with TF2 or TF1,
154
+ # because outputs are ordered differently for TF2 and TF1 models
155
+ outname = output_details [0 ]['name' ]
156
+
157
+ if ('StatefulPartitionedCall' in outname ): # This is a TF2 model
158
+ boxes_idx , classes_idx , scores_idx = 1 , 3 , 0
159
+ else : # This is a TF1 model
160
+ boxes_idx , classes_idx , scores_idx = 0 , 1 , 2
161
+
153
162
# Initialize frame rate calculation
154
163
frame_rate_calc = 1
155
164
freq = cv2 .getTickFrequency ()
@@ -182,10 +191,9 @@ def stop(self):
182
191
interpreter .invoke ()
183
192
184
193
# Retrieve detection results
185
- boxes = interpreter .get_tensor (output_details [0 ]['index' ])[0 ] # Bounding box coordinates of detected objects
186
- classes = interpreter .get_tensor (output_details [1 ]['index' ])[0 ] # Class index of detected objects
187
- scores = interpreter .get_tensor (output_details [2 ]['index' ])[0 ] # Confidence of detected objects
188
- #num = interpreter.get_tensor(output_details[3]['index'])[0] # Total number of detected objects (inaccurate and not needed)
194
+ boxes = interpreter .get_tensor (output_details [boxes_idx ]['index' ])[0 ] # Bounding box coordinates of detected objects
195
+ classes = interpreter .get_tensor (output_details [classes_idx ]['index' ])[0 ] # Class index of detected objects
196
+ scores = interpreter .get_tensor (output_details [scores_idx ]['index' ])[0 ] # Confidence of detected objects
189
197
190
198
# Loop over all detections and draw detection box if confidence is above minimum threshold
191
199
for i in range (len (scores )):
0 commit comments