Skip to content

Commit 1cb084c

Browse files
committed
优化代码
1 parent 6a15faf commit 1cb084c

File tree

3 files changed

+26
-43
lines changed

3 files changed

+26
-43
lines changed

plot.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def get_args():
4747
),
4848
formatter_class=argparse.RawTextHelpFormatter,
4949
)
50-
parser.add_argument("--dataset-json", type=str, help="Json file for datasets.")
51-
parser.add_argument("--method-json", type=str, help="Json file for methods.")
5250
parser.add_argument("--alias-yaml", type=str, help="Yaml file for datasets and methods alias.")
5351
parser.add_argument(
5452
"--style-cfg",
@@ -63,7 +61,6 @@ def get_args():
6361
nargs="+",
6462
help="Npy file for saving curve results.",
6563
)
66-
parser.add_argument("--our-method", type=str, help="Name of our method for highlighting it.")
6764
parser.add_argument(
6865
"--our-methods", type=str, nargs="+", help="Names of our methods for highlighting it."
6966
)
@@ -80,30 +77,6 @@ def get_args():
8077
default="pr",
8178
help="Mode for plotting. Default: pr",
8279
)
83-
parser.add_argument(
84-
"--include-methods",
85-
type=str,
86-
nargs="+",
87-
help="Names of only specific methods you want to evaluate.",
88-
)
89-
parser.add_argument(
90-
"--exclude-methods",
91-
type=str,
92-
nargs="+",
93-
help="Names of some specific methods you do not want to evaluate.",
94-
)
95-
parser.add_argument(
96-
"--include-datasets",
97-
type=str,
98-
nargs="+",
99-
help="Names of only specific datasets you want to evaluate.",
100-
)
101-
parser.add_argument(
102-
"--exclude-datasets",
103-
type=str,
104-
nargs="+",
105-
help="Names of some specific datasets you do not want to evaluate.",
106-
)
10780
parser.add_argument(
10881
"--separated-legend", action="store_true", help="Use the separated legend."
10982
)

readme.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ A Python-based **RGB/Co-RGB/RGB-D** salient object detection evaluation toolbox.
44

55
## TODO
66

7-
* [x] 更灵活的绘图配置脚本支持使用[符合matplotlib要求的](https://matplotlib.org/stable/tutorials/introductory/customizing.html#the-default-matplotlibrc-file)yaml文件来对绘图格式进行配置
7+
* [x] 更灵活的绘图配置脚本(支持使用[符合matplotlib要求的](https://matplotlib.org/stable/tutorials/introductory/customizing.html#the-default-matplotlibrc-file)yaml文件来对绘图格式进行配置)
88
* [ ] 添加测试脚本
99
* [ ] 添加更详细的注释
10-
* [ ] 考虑是否要使用yaml来替换配置策略其支持注释操作功能更丰富相比json更加灵活
10+
* [ ] 考虑是否要使用yaml来替换配置策略. 其支持注释操作, 功能更丰富, 相比json更加灵活
1111
* [ ] 优化xlsx导出的代码(? 导出CSV或许更好些? 既可以当做文本文件打开, 亦可使用Excel来进行整理)
1212
* [x] 多进程和多线程的支持.
1313
* [X] 剥离USVOS部分的代码, 让本仓库更专注一些, 相关代码已转移到另一个仓库[PyDavis16EvalToolbox](https://github.com/lartpang/PyDavis16EvalToolbox).
@@ -45,18 +45,18 @@ A Python-based **RGB/Co-RGB/RGB-D** salient object detection evaluation toolbox.
4545

4646
配置文件的例子:
4747
* python版本, 书写方便, 可以使用IDE的特性, 可以注释, 只需满足python语法. 但是需使用转换脚本进行转换.
48-
+ 可以参考 `examples` 文件夹中的 ~~`dataset_config.py``method_config.py`~~ `config_dataset_py_example.py``config_method_py_example.py`.
48+
- 可以参考 `examples` 文件夹中的 ~~`dataset_config.py``method_config.py`~~ `config_dataset_py_example.py``config_method_py_example.py`.
4949
* json版本, 更直接, 但是可能需要特定的插件支持. 需要满足json的语法. 不可以使用注释和末尾的逗号.
50-
+ 可以参考`examples`文件夹中的 `config_dataset_json_example.json``config_method_json_example.json`.
50+
- 可以参考`examples`文件夹中的 `config_dataset_json_example.json``config_method_json_example.json`.
5151

52-
具体使用流程更新于2022年4月24日:
52+
具体使用流程(更新于2022年4月24日):
5353
1. 先安装指标代码库: `pip install pysodmetrics`.
5454
- 评估代码来自本人的另一个项目:<https://github.com/lartpang/PySODMetrics>, 欢迎捉BUG!
5555
2. 配置不同数据集以及方法的路径信息:
56-
- 本项目依赖于json文件存放数据.
57-
- 但是本项目提供了`tools/info_py_to_json.py`来将python格式的信息转换为json文件. 使用方法可见`tools/readme.md`.
58-
- 准备好json文件后, 建议使用提供的`tools/check_path.py`来检查下路径信息是否正常.
59-
- **请务必确保*数据集字典的名字*和方法中配置不同*数据集字典的名字*一致**.
56+
- 本项目依赖于json文件存放数据`./examples`中已经提供了数据集和方法配置的例子:`config_dataset_json_example.json``config_method_json_example.json`,可以至直接修改他们用于后续步骤。
57+
- **[可选]** 但是本项目提供了`tools/info_py_to_json.py`来将python格式的信息(可见`./examples`中的提供的py格式的例子)转换为json文件. 使用方法可见`tools/readme.md`.
58+
- **[注意]** 请务必确保*数据集配置文件中数据集的名字*和方法配置文件中*数据集的名字*一致.
59+
- 准备好json文件后, 建议使用提供的`tools/check_path.py`来检查下json文件中的路径信息是否正常.
6060
3. 一切正常后, 可以开始评估了.
6161
- 评估脚本用法:`python eval.py --help`
6262
- 根据自己需求添加配置项并执行即可。如无异常, 会生成指定文件名的结果文件。如果不指定所有的文件,那么就直接输出结果,具体可见阅读`eval_all.py`的帮助信息。
@@ -65,7 +65,7 @@ A Python-based **RGB/Co-RGB/RGB-D** salient object detection evaluation toolbox.
6565
- 该脚本用法可见:`python plot.py --help`
6666
- 按照自己需求添加配置项并执行即可。最基本的一条是请按照子图数量合理指定配置文件中的`figure.figsize`项的数值。
6767
5. 可选:
68-
1. 使用`tools/converter.py`直接从生成的npy文件中导出latex表格代码.
68+
1. 使用 `tools/converter.py` 直接从生成的npy文件中导出latex表格代码.
6969

7070
## 相关文献
7171

@@ -128,6 +128,8 @@ A Python-based **RGB/Co-RGB/RGB-D** salient object detection evaluation toolbox.
128128

129129
## 更新日志
130130

131+
* 2022年5月15日
132+
- 代码优化
131133
* 2022年4月23日
132134
- 为了便于使用和配置,对大量代码进行了调整和修改,与之前版本相比,使用上也存在部分差异。
133135
- 评估部分:

tools/converter.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ def update_dict(parent_dict, sub_dict):
5151
results = {}
5252
for result_file in args.result_file:
5353
result = np.load(file=result_file, allow_pickle=True).item()
54-
update_dict(results, result)
54+
for dataset_name, method_infos in result.items():
55+
results.setdefault(dataset_name, {})
56+
for method_name, method_info in method_infos.items():
57+
results[dataset_name][method_name] = method_info
5558

5659
IMPOSSIBLE_UP_BOUND = 1
5760
IMPOSSIBLE_DOWN_BOUND = 0
5861

5962
# 读取数据
6063
dataset_names = sorted(list(results.keys()))
61-
metric_names = ["SM", "wFm", "MAE", "adpF", "avgF", "maxF", "adpE", "avgE", "maxE"]
64+
metric_names = ["SM", "wFm", "MAE", "adpE", "avgE", "maxE", "adpF", "avgF", "maxF"]
6265
method_names = sorted(list(set(chain(*[list(results[n].keys()) for n in dataset_names]))))
6366

6467
if args.config_file is not None:
@@ -115,10 +118,15 @@ def update_dict(parent_dict, sub_dict):
115118
IMPOSSIBLE_UP_BOUND if ori_metric_name.lower() == "mae" else IMPOSSIBLE_DOWN_BOUND
116119
)
117120
fiiled_dict = {k: fiiled_value for k in ori_metric_names}
118-
ori_column = [
119-
results[dataset_name].get(method_name, fiiled_dict)[ori_metric_name]
120-
for method_name in ori_method_names
121-
]
121+
ori_column = []
122+
for method_name in ori_method_names:
123+
method_result = results[dataset_name].get(method_name, fiiled_dict)
124+
if ori_metric_name not in method_result:
125+
raise KeyError(
126+
f"{ori_metric_name} must be contained in {list(method_result.keys())}"
127+
)
128+
ori_column.append(method_result[ori_metric_name])
129+
122130
column_for_index.append([x * round(1 - fiiled_value * 2) for x in ori_column])
123131
ori_columns.append(ori_column)
124132

0 commit comments

Comments
 (0)