bugfix: correcting for the background class
@@ -137,6 +137,9 @@ def main():
output_layer = graph.get_tensor_by_name(OUTPUT_LAYER_NAME+':0')
model_input_shape = input_layer.shape
+ model_output_shape = output_layer.shape
+ model_classes = model_output_shape[1]
+ bg_class_offset = model_classes-len(labels) # 1 means the labels represent classes 1..1000 and the background class 0 has to be skipped
if MODEL_DATA_LAYOUT == 'NHWC':
(samples, height, width, channels) = model_input_shape
@@ -147,6 +150,9 @@ def main():
print("Input layer: {}".format(input_layer) )
print("Output layer: {}".format(output_layer) )
print("Expected input shape: {}".format(model_input_shape) )
+ print("Output layer shape: {}".format(model_output_shape) )
+ print("Number of labels: {}".format(num_labels))
+ print("Background/unlabelled classes to skip: {}".format(bg_class_offset))
print("Data normalization: {}".format(MODEL_NORMALIZE_DATA) )
print("")
@@ -188,7 +194,8 @@ def main():
# Process results
for index_in_batch in range(BATCH_SIZE):
- softmax_vector = batch_results[index_in_batch][:num_labels]
+ softmax_vector = batch_results[index_in_batch][bg_class_offset:] # skipping the background class on the left (if present)
+# softmax_vector = batch_results[index_in_batch][:num_labels]
global_index = batch_index * BATCH_SIZE + index_in_batch
res_file = os.path.join(RESULT_DIR, image_list[global_index])
with open(res_file + '.txt', 'w') as f:
