Skip to content

Commit 6c97b0c

Browse files
committed
调整细节,并更新指标库的版本。
1 parent 6569d47 commit 6c97b0c

File tree

3 files changed

+30
-65
lines changed

3 files changed

+30
-65
lines changed

readme.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ A Python-based image binary segmentation evaluation toolbox.
77
## 一些规划
88

99
* [ ] 向执行脚本中添加配置信息合理行检测.
10-
* 更灵活的配置脚本
10+
* 更灵活的配置脚本.
1111
+ [ ] 使用[符合matplotlib要求的](https://matplotlib.org/stable/tutorials/introductory/customizing.html#the-default-matplotlibrc-file)的 yaml 文件来控制绘图格式.
1212
+ [ ] 是否应该使用更加灵活强大的配置格式, 例如 yaml 或者 toml 来替换配置策略.
13-
* [ ] 添加测试脚本
14-
* [ ] 添加更详细的注释
15-
* 优化导出代码
16-
+ [ ] 导出到 XLSX 文件的代码
13+
* [ ] 添加测试脚本.
14+
* [ ] 添加更详细的注释.
15+
* 优化导出评估结果的代码.
16+
+ [x] 实现导出 XLSX 文件的代码.
17+
+ [ ] 优化导出到 XLSX 文件的代码.
1718
+ [ ] 是否应该使用 CSV 这样的文本格式更好些? 既可以当做文本文件打开, 亦可使用Excel来进行整理.
18-
* [ ] 完善关于分组数据的代码, 即CoSOD、Video Binary Segmentation等任务的支持.
19+
* [ ] 使用 `pathlib.Path` 替换 `os.path`.
20+
* [ ] 完善关于分组数据的代码, 即 CoSOD、Video Binary Segmentation 等任务的支持.
1921
* [x] 支持并发策略加速计算. 目前保留了多线程支持, 剔除了之前的多进程代码.
2022
* [X] 剥离 USVOS 代码到另一个仓库 [PyDavis16EvalToolbox](https://github.com/lartpang/PyDavis16EvalToolbox).
2123
* [X] 基于 github page 服务自动化生成结果汇总网页, 并支持基于某个指标进行排序的支持.
@@ -59,15 +61,17 @@ A Python-based image binary segmentation evaluation toolbox.
5961

6062
### 安装依赖
6163

62-
先安装指标代码库: `pip install pysodmetrics` .
64+
先安装相关依赖库: `pip install -r requirements.txt` .
6365

64-
这来自本人的另一个项目:[PySODMetrics](https://github.com/lartpang/PySODMetrics), 欢迎捉BUG!
66+
其中指标评估是基于本人的另一个项目: [PySODMetrics](https://github.com/lartpang/PySODMetrics), 欢迎捉BUG!
6567

6668
### 配置数据集与方法预测的路径信息
6769

6870
本项目依赖于json文件存放数据, `./examples` 中已经提供了数据集和方法配置的例子: `config_dataset_json_example.json``config_method_json_example.json` , 可以至直接修改他们用于后续步骤.
6971

70-
[注意] 请务必确保*数据集配置文件中数据集的名字*和方法配置文件中*数据集的名字*一致. 准备好json文件后, 建议使用提供的 `tools/check_path.py` 来检查下json文件中的路径信息是否正常.
72+
[注意]
73+
* 请注意, 由于本项目依赖于 OpenCV 读取图片, 所以请确保路径字符串不包含非 ASCII 字符.
74+
* 请务必确保*数据集配置文件中数据集的名字*和方法配置文件中*数据集的名字*一致. 准备好json文件后, 建议使用提供的 `tools/check_path.py` 来检查下json文件中的路径信息是否正常.
7175

7276
<details>
7377
<summary>
@@ -191,10 +195,10 @@ python tools/check_path.py --method-jsons configs/methods/rgb-sod/rgb_sod_method
191195
# --curves-npy 输出曲线数据到 output/rgb_sod/curves.npy
192196
# --record-txt 输出评估结果文本到 output/rgb_sod/results.txt
193197
# --record-xlsx 输出评估结果到excel文档 output/rgb_sod/results.xlsx
194-
# --metric-names 所有结果仅包含指标 mae fm em sm wfm 对应的信息
195-
# --include-methods 评估过程仅包含 configs/methods/rgb-sod/rgb_sod_methods.json 中包含的方法 MINet_R50_2020 GateNet_2020
196-
# --include-datasets 评估过程仅包含 configs/datasets/rgb_sod.json 中包含的数据集 PASCAL-S ECSSD
197-
python eval.py --dataset-json configs/datasets/rgb_sod.json --method-json configs/methods/rgb-sod/rgb_sod_methods.json --metric-npy output/rgb_sod/metrics.npy --curves-npy output/rgb_sod/curves.npy --record-txt output/rgb_sod/results.txt --record-xlsx output/rgb_sod/results.xlsx --metric-names mae fm em sm wfm --include-methods MINet_R50_2020 GateNet_2020 --include-datasets PASCAL-S ECSSD
198+
# --metric-names 所有结果仅包含给定指标的信息
199+
# --include-methods 评估过程仅包含 configs/methods/rgb-sod/rgb_sod_methods.json 中的给定方法
200+
# --include-datasets 评估过程仅包含 configs/datasets/rgb_sod.json 中的给定数据集
201+
python eval.py --dataset-json configs/datasets/rgb_sod.json --method-json configs/methods/rgb-sod/rgb_sod_methods.json --metric-npy output/rgb_sod/metrics.npy --curves-npy output/rgb_sod/curves.npy --record-txt output/rgb_sod/results.txt --record-xlsx output/rgb_sod/results.xlsx --metric-names sm wfm mae fmeasure em --include-methods MINet_R50_2020 GateNet_2020 --include-datasets PASCAL-S ECSSD
198202

199203
# 得到曲线数据文件,即这里的 output/rgb_sod/curves.npy 文件后,就可以开始绘制图像了
200204

@@ -282,6 +286,7 @@ python plot.py --style-cfg examples/single_row_style.yml --num-rows 1 --curves-n
282286
1. 提供更丰富的指标的支持。
283287
2. 更新`readme.md`和示例文件。
284288
3. 提供更灵活的接口。
289+
4. 更新指标库版本。
285290
* 2022年5月15日
286291
- 代码优化
287292
* 2022年4月23日

requirements.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Automatically generated by https://github.com/damnever/pigar.
22

3-
# PySODEvalToolkit/utils/misc.py: 6
4-
Pillow == 8.1.2
5-
63
# PySODEvalToolkit/plot.py: 6
74
# PySODEvalToolkit/tools/converter.py: 10
85
PyYAML == 5.4.1
@@ -42,7 +39,7 @@ openpyxl == 3.0.7
4239
# PySODEvalToolkit/metrics/extra_metrics.py: 3
4340
# PySODEvalToolkit/untracked/collect_results.py: 9
4441
# PySODEvalToolkit/utils/recorders/metric_recorder.py: 7
45-
pysodmetrics == 1.3.0
42+
pysodmetrics == 1.4.0
4643

4744
# PySODEvalToolkit/utils/print_formatter.py: 3
4845
tabulate == 0.8.9

utils/misc.py

+11-48
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import cv2
77
import numpy as np
8-
from PIL import Image
98

109

1110
def get_ext(path_list):
@@ -145,7 +144,7 @@ def get_name_with_group_list(
145144
return name_list
146145

147146

148-
def get_list_with_postfix(dataset_path: str, postfix: str):
147+
def get_list_with_suffix(dataset_path: str, suffix: str):
149148
name_list = []
150149
if os.path.isfile(dataset_path):
151150
print(f" ++>> {dataset_path} is a file. <<++ ")
@@ -158,45 +157,12 @@ def get_list_with_postfix(dataset_path: str, postfix: str):
158157
else:
159158
print(f" ++>> {dataset_path} is a folder. <<++ ")
160159
name_list = [
161-
os.path.splitext(f)[0] for f in os.listdir(dataset_path) if f.endswith(postfix)
160+
os.path.splitext(f)[0] for f in os.listdir(dataset_path) if f.endswith(suffix)
162161
]
163162
name_list = list(set(name_list))
164163
return name_list
165164

166165

167-
def rgb_loader(path):
168-
with open(path, "rb") as f:
169-
img = Image.open(f)
170-
return img.convert("L")
171-
172-
173-
def binary_loader(path):
174-
assert os.path.exists(path), f"`{path}` does not exist."
175-
with open(path, "rb") as f:
176-
img = Image.open(f)
177-
return img.convert("L")
178-
179-
180-
def load_data(pre_root, gt_root, name, postfixs):
181-
pre = binary_loader(os.path.join(pre_root, name + postfixs[0]))
182-
gt = binary_loader(os.path.join(gt_root, name + postfixs[1]))
183-
return pre, gt
184-
185-
186-
def normalize_pil(pre, gt):
187-
gt = np.asarray(gt)
188-
pre = np.asarray(pre)
189-
gt = gt / (gt.max() + 1e-8)
190-
gt = np.where(gt > 0.5, 1, 0)
191-
max_pre = pre.max()
192-
min_pre = pre.min()
193-
if max_pre == min_pre:
194-
pre = pre / 255
195-
else:
196-
pre = (pre - min_pre) / (max_pre - min_pre)
197-
return pre, gt
198-
199-
200166
def make_dir(path):
201167
if not os.path.exists(path):
202168
print(f"`{path}` does not exist,we will create it.")
@@ -206,16 +172,13 @@ def make_dir(path):
206172
print(f"`{path}`已存在")
207173

208174

209-
def imread_wich_checking(path, for_color: bool = True, with_cv2: bool = True) -> np.ndarray:
175+
def imread_with_checking(path, for_color: bool = True) -> np.ndarray:
210176
assert os.path.exists(path=path) and os.path.isfile(path=path), path
211-
if with_cv2:
212-
if for_color:
213-
data = cv2.imread(path, flags=cv2.IMREAD_COLOR)
214-
data = cv2.cvtColor(data, cv2.COLOR_BGR2RGB)
215-
else:
216-
data = cv2.imread(path, flags=cv2.IMREAD_GRAYSCALE)
177+
if for_color:
178+
data = cv2.imread(path, flags=cv2.IMREAD_COLOR)
179+
data = cv2.cvtColor(data, cv2.COLOR_BGR2RGB)
217180
else:
218-
data = np.array(Image.open(path).convert("RGB" if for_color else "L"))
181+
data = cv2.imread(path, flags=cv2.IMREAD_GRAYSCALE)
219182
return data
220183

221184

@@ -233,8 +196,8 @@ def get_gt_pre_with_name(
233196
img_path = os.path.join(pre_root, pre_prefix + img_name + pre_suffix)
234197
gt_path = os.path.join(gt_root, gt_prefix + img_name + gt_suffix)
235198

236-
pre = imread_wich_checking(img_path, for_color=False)
237-
gt = imread_wich_checking(gt_path, for_color=False)
199+
pre = imread_with_checking(img_path, for_color=False)
200+
gt = imread_with_checking(gt_path, for_color=False)
238201

239202
if pre.shape != gt.shape:
240203
pre = cv2.resize(pre, dsize=gt.shape[::-1], interpolation=cv2.INTER_LINEAR).astype(
@@ -271,8 +234,8 @@ def get_gt_pre_with_name_and_group(
271234
img_path = os.path.join(pre_root, pre_prefix + file_name + pre_suffix)
272235
gt_path = os.path.join(gt_root, gt_prefix + file_name + gt_suffix)
273236

274-
pre = imread_wich_checking(img_path, for_color=False)
275-
gt = imread_wich_checking(gt_path, for_color=False)
237+
pre = imread_with_checking(img_path, for_color=False)
238+
gt = imread_with_checking(gt_path, for_color=False)
276239

277240
if pre.shape != gt.shape:
278241
pre = cv2.resize(pre, dsize=gt.shape[::-1], interpolation=interpolation).astype(np.uint8)

0 commit comments

Comments
 (0)