Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] tools/split_dataset_list.py 划分数据集异常 #2070

Closed
GreatV opened this issue Apr 29, 2022 · 1 comment
Closed

[Bug] tools/split_dataset_list.py 划分数据集异常 #2070

GreatV opened this issue Apr 29, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@GreatV
Copy link

GreatV commented Apr 29, 2022

环境信息

  1. PaddleSeg版本:PaddleSeg release/2.5
  2. PaddlePaddle版本:PaddlePaddle 2.2
  3. 操作系统信息:Linux
  4. Python版本号:Python3.7

使用的脚本命令

export dataset_root=/home/real_data
export images_dir_name=/home/real_data/images
export labels_dir_name=/home/real_data/annotations
python tools/split_dataset_list.py ${dataset_root} ${images_dir_name} ${labels_dir_name} \
    --split 0.7 0.2 0.1

报错信息

Traceback (most recent call last):
  File "tools/split_dataset_list.py", line 151, in <module>
    generate_list(args)
  File "tools/split_dataset_list.py", line 82, in generate_list
    raise ValueError("划分比例之和必须为1")
ValueError: 划分比例之和必须为1

原因分析

此处对浮点数进行了不等于判断

if sum(args.split) != 1.0:
raise ValueError("划分比例之和必须为1")

实际上不能直接对浮点数进行等于或不等于判读

Python 3.7.5 (default, Dec  9 2021, 17:04:37) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.7 + 0.2 + 0.1
0.9999999999999999
>>> 

修改建议

添加或者使用如下类似的判断

def float_equal(a: float, b: float) -> bool:
    allowed_error = 1e-8
    return abs(a - b) <= allowed_error
    if not float_equal(sum(args.split), 1.0):
        raise ValueError("划分比例之和必须为1")
@GreatV GreatV added the bug Something isn't working label Apr 29, 2022
@juncaipeng
Copy link
Collaborator

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants