diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..fbca22537 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +results/ diff --git a/main.py b/main.py index 7e15c1a69..ea1dde619 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ parser.add_argument('-q', '--quiet', help="minimalistic console output.", action="store_true") # argparse receiving list of classes to be ignored parser.add_argument('-i', '--ignore', nargs='+', type=str, help="ignore a list of classes.") -# argparse receiving list of classes with specific IoU +# argparse receiving list of classes with specific IoU (e.g., python main.py --set-class-iou person 0.7) parser.add_argument('--set-class-iou', nargs='+', type=str, help="set IoU for a specific class.") args = parser.parse_args() @@ -230,7 +230,10 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out # if true_p_bar != "": """ - Special case to draw in (green=true predictions) & (red=false predictions) + Special case to draw in: + - green -> TP: True Positives (object detected and matches ground-truth) + - red -> FP: False Positives (object detected but does not match ground-truth) + - orange -> FN: False Negatives (object not detected but present in the ground-truth) """ fp_sorted = [] tp_sorted = [] @@ -311,11 +314,11 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out plt.close() """ - Create a "tmp_files/" and "results/" directory + Create a ".temp_files/" and "results/" directory """ -tmp_files_path = "tmp_files" -if not os.path.exists(tmp_files_path): # if it doesn't exist already - os.makedirs(tmp_files_path) +TEMP_FILES_PATH = ".temp_files" +if not os.path.exists(TEMP_FILES_PATH): # if it doesn't exist already + os.makedirs(TEMP_FILES_PATH) results_files_path = "results" if os.path.exists(results_files_path): # if it exist already # reset the results directory @@ -396,7 +399,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out # dump bounding_boxes into a ".json" file - with open(tmp_files_path + "/" + file_id + "_ground_truth.json", 'w') as outfile: + with open(TEMP_FILES_PATH + "/" + file_id + "_ground_truth.json", 'w') as outfile: json.dump(bounding_boxes, outfile) gt_classes = list(gt_counter_per_class.keys()) @@ -466,7 +469,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out #print(bounding_boxes) # sort predictions by decreasing confidence bounding_boxes.sort(key=lambda x:float(x['confidence']), reverse=True) - with open(tmp_files_path + "/" + class_name + "_predictions.json", 'w') as outfile: + with open(TEMP_FILES_PATH + "/" + class_name + "_predictions.json", 'w') as outfile: json.dump(bounding_boxes, outfile) """ @@ -484,7 +487,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out """ Load predictions of that class """ - predictions_file = tmp_files_path + "/" + class_name + "_predictions.json" + predictions_file = TEMP_FILES_PATH + "/" + class_name + "_predictions.json" predictions_data = json.load(open(predictions_file)) """ @@ -519,7 +522,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out img = cv2.copyMakeBorder(img, 0, bottom_border, 0, 0, cv2.BORDER_CONSTANT, value=BLACK) # assign prediction to ground truth object if any # open ground-truth with that file_id - gt_file = tmp_files_path + "/" + file_id + "_ground_truth.json" + gt_file = TEMP_FILES_PATH + "/" + file_id + "_ground_truth.json" ground_truth_data = json.load(open(gt_file)) ovmax = -1 gt_match = -1 @@ -706,8 +709,8 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out results_file.write(text + "\n") print(text) -# remove the tmp_files directory -shutil.rmtree(tmp_files_path) +# remove the temp_files directory +shutil.rmtree(TEMP_FILES_PATH) """ Count total of Predictions @@ -786,7 +789,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out # end Plot title x_label = "Number of objects per class" output_path = results_files_path + "/Predicted Objects Info.png" - to_show = False + to_show = True plot_color = 'forestgreen' true_p_bar = count_true_positives draw_plot_func(