|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import argparse |
| 3 | +import os |
| 4 | +import textwrap |
| 5 | +import warnings |
| 6 | + |
| 7 | +from metrics import cal_sod_matrics |
| 8 | +from utils.generate_info import get_datasets_info, get_methods_info |
| 9 | +from utils.misc import make_dir |
| 10 | +from utils.recorders import METRIC_MAPPING |
| 11 | + |
| 12 | + |
| 13 | +def get_args(): |
| 14 | + parser = argparse.ArgumentParser( |
| 15 | + description=textwrap.dedent( |
| 16 | + r""" |
| 17 | + INCLUDE: |
| 18 | +
|
| 19 | + - F-measure-Threshold Curve |
| 20 | + - Precision-Recall Curve |
| 21 | + - MAE |
| 22 | + - weighted F-measure |
| 23 | + - S-measure |
| 24 | + - max/average/adaptive F-measure |
| 25 | + - max/average/adaptive E-measure |
| 26 | + - max/average Precision |
| 27 | + - max/average Sensitivity |
| 28 | + - max/average Specificity |
| 29 | + - max/average F-measure |
| 30 | + - max/average Dice |
| 31 | + - max/average IoU |
| 32 | +
|
| 33 | + NOTE: |
| 34 | +
|
| 35 | + - Our method automatically calculates the intersection of `pre` and `gt`. |
| 36 | + - Currently supported pre naming rules: `prefix + gt_name_wo_ext + suffix_w_ext` |
| 37 | +
|
| 38 | + EXAMPLES: |
| 39 | +
|
| 40 | + python eval_all.py \ |
| 41 | + --dataset-json configs/datasets/json/rgbd_sod.json \ |
| 42 | + --method-json configs/methods/json/rgbd_other_methods.json configs/methods/json/rgbd_our_method.json --metric-npy output/rgbd_metrics.npy \ |
| 43 | + --curves-npy output/rgbd_curves.npy \ |
| 44 | + --record-tex output/rgbd_results.txt |
| 45 | + """ |
| 46 | + ), |
| 47 | + formatter_class=argparse.RawTextHelpFormatter, |
| 48 | + ) |
| 49 | + parser.add_argument("--dataset-json", required=True, type=str, help="Json file for datasets.") |
| 50 | + parser.add_argument( |
| 51 | + "--method-json", required=True, nargs="+", type=str, help="Json file for methods." |
| 52 | + ) |
| 53 | + parser.add_argument("--metric-npy", type=str, help="Npy file for saving metric results.") |
| 54 | + parser.add_argument("--curves-npy", type=str, help="Npy file for saving curve results.") |
| 55 | + parser.add_argument("--record-txt", type=str, help="Txt file for saving metric results.") |
| 56 | + parser.add_argument("--to-overwrite", action="store_true", help="To overwrite the txt file.") |
| 57 | + parser.add_argument("--record-xlsx", type=str, help="Xlsx file for saving metric results.") |
| 58 | + parser.add_argument( |
| 59 | + "--include-methods", |
| 60 | + type=str, |
| 61 | + nargs="+", |
| 62 | + help="Names of only specific methods you want to evaluate.", |
| 63 | + ) |
| 64 | + parser.add_argument( |
| 65 | + "--exclude-methods", |
| 66 | + type=str, |
| 67 | + nargs="+", |
| 68 | + help="Names of some specific methods you do not want to evaluate.", |
| 69 | + ) |
| 70 | + parser.add_argument( |
| 71 | + "--include-datasets", |
| 72 | + type=str, |
| 73 | + nargs="+", |
| 74 | + help="Names of only specific datasets you want to evaluate.", |
| 75 | + ) |
| 76 | + parser.add_argument( |
| 77 | + "--exclude-datasets", |
| 78 | + type=str, |
| 79 | + nargs="+", |
| 80 | + help="Names of some specific datasets you do not want to evaluate.", |
| 81 | + ) |
| 82 | + parser.add_argument( |
| 83 | + "--num-workers", |
| 84 | + type=int, |
| 85 | + default=4, |
| 86 | + help="Number of workers for multi-threading or multi-processing. Default: 4", |
| 87 | + ) |
| 88 | + parser.add_argument( |
| 89 | + "--num-bits", |
| 90 | + type=int, |
| 91 | + default=3, |
| 92 | + help="Number of decimal places for showing results. Default: 3", |
| 93 | + ) |
| 94 | + parser.add_argument( |
| 95 | + "--metric-names", |
| 96 | + type=str, |
| 97 | + nargs="+", |
| 98 | + default=["mae", "fm", "em", "sm", "wfm"], |
| 99 | + choices=METRIC_MAPPING.keys(), |
| 100 | + help="Names of metrics", |
| 101 | + ) |
| 102 | + args = parser.parse_args() |
| 103 | + |
| 104 | + if args.metric_npy is not None: |
| 105 | + make_dir(os.path.dirname(args.metric_npy)) |
| 106 | + if args.curves_npy is not None: |
| 107 | + make_dir(os.path.dirname(args.curves_npy)) |
| 108 | + if args.record_txt is not None: |
| 109 | + make_dir(os.path.dirname(args.record_txt)) |
| 110 | + if args.record_xlsx is not None: |
| 111 | + make_dir(os.path.dirname(args.record_xlsx)) |
| 112 | + if args.to_overwrite and not args.record_txt: |
| 113 | + warnings.warn("--to-overwrite only works with a valid --record-txt") |
| 114 | + return args |
| 115 | + |
| 116 | + |
| 117 | +def main(): |
| 118 | + args = get_args() |
| 119 | + |
| 120 | + # 包含所有数据集信息的字典 |
| 121 | + datasets_info = get_datasets_info( |
| 122 | + datastes_info_json=args.dataset_json, |
| 123 | + include_datasets=args.include_datasets, |
| 124 | + exclude_datasets=args.exclude_datasets, |
| 125 | + ) |
| 126 | + # 包含所有待比较模型结果的信息的字典 |
| 127 | + methods_info = get_methods_info( |
| 128 | + methods_info_jsons=args.method_json, |
| 129 | + for_drawing=True, |
| 130 | + include_methods=args.include_methods, |
| 131 | + exclude_methods=args.exclude_methods, |
| 132 | + ) |
| 133 | + |
| 134 | + # 确保多进程在windows上也可以正常使用 |
| 135 | + cal_sod_matrics.cal_sod_matrics( |
| 136 | + sheet_name="Results", |
| 137 | + to_append=not args.to_overwrite, |
| 138 | + txt_path=args.record_txt, |
| 139 | + xlsx_path=args.record_xlsx, |
| 140 | + methods_info=methods_info, |
| 141 | + datasets_info=datasets_info, |
| 142 | + curves_npy_path=args.curves_npy, |
| 143 | + metrics_npy_path=args.metric_npy, |
| 144 | + num_bits=args.num_bits, |
| 145 | + num_workers=args.num_workers, |
| 146 | + use_mp=False, |
| 147 | + metric_names=args.metric_names, |
| 148 | + ncols_tqdm=119, |
| 149 | + ) |
| 150 | + |
| 151 | + |
| 152 | +if __name__ == "__main__": |
| 153 | + main() |
0 commit comments