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

Config loader adds an extra "./" when inputting file paths #3387

Closed
1 task done
fatbringer opened this issue Jul 19, 2023 · 5 comments
Closed
1 task done

Config loader adds an extra "./" when inputting file paths #3387

fatbringer opened this issue Jul 19, 2023 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@fatbringer
Copy link

fatbringer commented Jul 19, 2023

问题确认 Search before asking

  • 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.

请提出你的问题 Please ask your question

I am following the format of this predict.py file for paddleseg found at https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.8/tools/predict.py

I have put my config yaml file in folder called "paddleSeg_files"

sys.path.insert(1, 'paddleSeg_files')
config_file_path = "pp_liteseg_stdc2_cityscapes_1024x512_scale1.0_160k.yml"
cfg = Config("paddleSeg_files/" + config_file_path)

[Errno 2] No such file or directory: 'paddleSeg_files/./pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml'

another error i got

config_file_path = "pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml"
cfg = Config("paddleSeg_files/" + config_file_path)

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[29], line 3
      1 config_file_path = os.path.join('paddleSeg_files', 'pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml')
----> 3 cfg = Config(config_file_path)
      4 builder = SegBuilder(cfg)
      5 test_config = merge_test_config(cfg, args)

File ~/Desktop/pyenvs/newpy39/lib/python3.9/site-packages/paddleseg/cvlibs/config.py:73, in Config.__init__(self, path, learning_rate, batch_size, iters, opts, checker)
     68 assert os.path.exists(path), \
     69     'Config path ({}) does not exist'.format(path)
     70 assert path.endswith('yml') or path.endswith('yaml'), \
     71     'Config file ({}) should be yaml format'.format(path)
---> 73 self.dic = self._parse_from_yaml(path)
     74 self.dic = self.update_config_dict(
     75     self.dic,
     76     learning_rate=learning_rate,
     77     batch_size=batch_size,
     78     iters=iters,
     79     opts=opts)
     81 if checker is None:

File ~/Desktop/pyenvs/newpy39/lib/python3.9/site-packages/paddleseg/cvlibs/config.py:136, in Config._parse_from_yaml(cls, path, *args, **kwargs)
    134 @classmethod
    135 def _parse_from_yaml(cls, path: str, *args, **kwargs) -> dict:
--> 136     return parse_from_yaml(path, *args, **kwargs)

File ~/Desktop/pyenvs/newpy39/lib/python3.9/site-packages/paddleseg/cvlibs/config.py:169, in parse_from_yaml(path)
    167     for bf in base_files:
    168         base_path = os.path.join(os.path.dirname(path), bf)
--> 169         base_dic = parse_from_yaml(base_path)
    170         dic = merge_config_dicts(dic, base_dic)
    172 return dic

File ~/Desktop/pyenvs/newpy39/lib/python3.9/site-packages/paddleseg/cvlibs/config.py:160, in parse_from_yaml(path)
    158 def parse_from_yaml(path: str):
    159     """Parse a yaml file and build config"""
--> 160     with codecs.open(path, 'r', 'utf-8') as file:
    161         dic = yaml.load(file, Loader=yaml.FullLoader)
    163     if _BASE_KEY in dic:

File /usr/lib/python3.9/codecs.py:905, in open(filename, mode, encoding, errors, buffering)
    901 if encoding is not None and \
    902    'b' not in mode:
    903     # Force opening of the file in binary mode
    904     mode = mode + 'b'
--> 905 file = builtins.open(filename, mode, buffering)
    906 if encoding is None:
    907     return file

FileNotFoundError: [Errno 2] No such file or directory: 'paddleSeg_files/../_base_/cityscapes.yml'

Why is there additional ./ between the folders? Or other folder paths being inserted between? There is no extra folder in actual fact.

Environment:
Ubuntu 22.04
paddlepaddle_gpu 2.5.0
paddleseg-2.8.0
Python 3.9
CUDA 11.7
Cudnn 7.8
gcc gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0

@fatbringer fatbringer added the question Further information is requested label Jul 19, 2023
@Asthestarsfalll
Copy link
Contributor

Please use absolute path

@fatbringer
Copy link
Author

Hey @Asthestarsfalll thanks for responding

I have tried using aboslute path too but it doesnt work
for example

config_file_path = '/home/username/Desktop/enhancements/paddleSeg_Jul2023/paddleSeg_files/pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml'


FileNotFoundError: [Errno 2] No such file or directory: '/home/username/Desktop/enhancements/paddleSeg_Jul2023/paddleSeg_files/../_base_/cityscapes.yml'

@Asthestarsfalll
Copy link
Contributor

Hey @Asthestarsfalll thanks for responding

I have tried using aboslute path too but it doesnt work for example

config_file_path = '/home/username/Desktop/enhancements/paddleSeg_Jul2023/paddleSeg_files/pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml'


FileNotFoundError: [Errno 2] No such file or directory: '/home/username/Desktop/enhancements/paddleSeg_Jul2023/paddleSeg_files/../_base_/cityscapes.yml'

Sorry, my bad.
You should put all needed config files into paddleSeg_files
According the error info, you need to create a folder named _base_, and put cityscapes.yml into it.
Or you can remove all _base_ in pp_liteseg_stdc1_cityscapes_1024x512_scale0.5_160k.yml, and put all files in the same level.
For more details, you can refer to the inheritance mechanism of paddleseg config.
The refering code is here

@fatbringer
Copy link
Author

I see. I understand now that the yaml references another yaml file. I have changed base path to refer correctly. THank you!

@ToddBear
Copy link
Collaborator

以上回答已经充分解答了问题,如果有新的问题欢迎随时提交issue,或者在此条issue下继续回复~
我们开启了飞桨套件的ISSUE攻关活动,欢迎感兴趣的开发者参加:PaddlePaddle/PaddleOCR#10223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants