YouHuang67 / InterFormer

MIT License
35 stars 5 forks source link

AttributeError: 'ConfigDict' object has no attribute 'test' #2

Open WangBingJian233 opened 1 year ago

WangBingJian233 commented 1 year ago

Hello author, thank you very much for your outstanding contribution. In Evaluation,To evaluate on SBD with InterFormer-Tiny, run: CUDA_VISIBLE_DEVICES=0,1,2,3 bash tools/dist_clicktest.sh work_dirs/interformer_tiny_coco_lvis_320k/iter_320000.pth 4 --dataset sbd --size_divisor 32. I encountered an error while running:Traceback (most recent call last): File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 316, in main() File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 219, in main dataset = build_dataset(cfg.data.test) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/mmcv/utils/config.py", line 50, in getattr raise ex AttributeError: 'ConfigDict' object has no attribute 'test' How should I solve it?

The full output of the error: (py38_wbj) student1@user-PowerEdge-R555:~$ CUDA_VISIBLE_DEVICES=0,1 bash /home/student1/wbj/InterFormer/tools/dist_clicktest.sh "/home/student1/wbj/InterFormer/work_dirs/interformer_tiny_coco_lvis_320k/iter_320000.pth" 2 --dataset berkeley --size_divisor 32 /home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launch.py:178: FutureWarning: The module torch.distributed.launch is deprecated and will be removed in future. Use torchrun. Note that --use_env is set by default in torchrun. If your script expects --local_rank argument to be set, please change it to read from os.environ['LOCAL_RANK'] instead. See https://pytorch.org/docs/stable/distributed.html#launch-utility for further instructions

warnings.warn( WARNING:torch.distributed.run:


Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.


2023-07-05 01:55:19,481 - mmseg - INFO - Multi-processing start method is None 2023-07-05 01:55:19,482 - mmseg - INFO - OpenCV num_threads is 32 2023-07-05 01:55:19,482 - mmseg - INFO - OMP num threads is 1 2023-07-05 01:55:20,168 - mmseg - INFO - Multi-processing start method isNone 2023-07-05 01:55:20,169 - mmseg - INFO - OpenCV num_threads is32 2023-07-05 01:55:20,169 - mmseg - INFO - OMP num threads is 1 Traceback (most recent call last): File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 316, in main() File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 219, in main dataset = build_dataset(cfg.data.test) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/mmcv/utils/config.py", line 50, in getattr raise ex AttributeError: 'ConfigDict' object has no attribute 'test' Traceback (most recent call last): File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 316, in main() File "/home/student1/wbj/InterFormer/tools/clicktest.py", line 219, in main dataset = build_dataset(cfg.data.test) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/mmcv/utils/config.py", line 50, in getattr raise ex AttributeError: 'ConfigDict' object has no attribute 'test' ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 11982) of binary: /home/student1/anaconda3/envs/py38_wbj/bin/python Traceback (most recent call last): File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launch.py", line 193, in main() File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launch.py", line 189, in main launch(args) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launch.py", line 174, in launch run(args) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/run.py", line 752, in run elastic_launch( File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 131, in call return launch_agent(self._config, self._entrypoint, list(args)) File "/home/student1/anaconda3/envs/py38_wbj/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 245, in launch_agent raise ChildFailedError( torch.distributed.elastic.multiprocessing.errors.ChildFailedError:

/home/student1/wbj/InterFormer/tools/clicktest.py FAILED

Failures: [1]: time : 2023-07-05_01:55:22 host : user-PowerEdge-R555 rank : 1 (local_rank: 1) exitcode : 1 (pid: 15984) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html

Root Cause (first observed failure): [0]: time : 2023-07-05_01:55:22 host : user-PowerEdge-R555 rank : 0 (local_rank: 0) exitcode : 1 (pid: 15982) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html

YouHuang67 commented 1 year ago

Hello,

The error message you've shared suggests that there might be an issue with how the 'test' attribute is being set in the 'merge_from_dict' function on line 135 in 'clicktest.py'. The way this function operates could vary between different versions of the library, which could be the root of your issue.

Could you confirm your library version for us? Meanwhile, you might also want to check your MMCV version:

import mmcv
print(mmcv.__version__)
WangBingJian233 commented 1 year ago

I installed the various packages according to the prompts, after import mmcv and print(mmcv.version), my mmcv version is 1.6.0

YouHuang67 commented 1 year ago

Considering I can't directly test in your environment, I recommend using an additional configuration file for testing, strictly following the basic paradigm of open-mmlab. Here are the steps:

1) In your test configuration file directory, i.e., work_dirs/interformer_tiny_coco_lvis_320k, create a new folder named intertest_sbd (or any other name of your choice). Within intertest_sbd, create a new configuration file config.py. Below is an example (for SBD, the content is taken from the set_test_cfg function starting from line 56 in clicktest.py):

_base_ = ['../interformer_tiny_coco_lvis_320k.py']  # Note: This must point to your previous test configuration file

pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadSBDAnnotations'),
    dict(
        type='Resize',
        img_scale=None,
        ratio_range=(1.0, 1.0),
        keep_ratio=True),
    dict(type='RandomFlip', prob=0.0),
    dict(
        type='Normalize',
        mean=[123.675, 116.28, 103.53],
        std=[58.395, 57.12, 57.375],
        to_rgb=True),
    dict(
        type='Pad',
        size=None,
        size_divisor=32,
        pad_val=0,
        seg_pad_val=0),
    dict(
        type='ObjectSampler',
        num_samples=1,
        max_num_merged_objects=1,
        min_area_ratio=0.0),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=('img', 'gt_semantic_seg'))
]

data = dict(
    test=dict(
        type=dataset,
        data_root='data/sbd/benchmark_RELEASE/dataset',
        pipeline=pipeline
))

model = dict(
    test_cfg=dict(
        num_clicks=20,
        inner_radius=5,
        outer_radius=0
))

2) Comment out line 178 in clicktest.py which is cfg = set_test_cfg(cfg, args). This is because the above configuration already realizes this part to prevent overwriting.

3) Use ln -s src_file tar_file to create a symbolic link to your downloaded iter_320000.pth weight file in the intertest_sbd folder (i.e., in the same directory as config.py), and then start the test command. Make sure to change the path to intertest_sbd. Also, note that when using ln -s, the source path must be an absolute path.

4) Lastly, please note that you can refer to the set_test_cfg function in clicktest.py to adapt this example for testing other datasets.

WangBingJian233 commented 1 year ago

考虑到我不能直接在您的环境中进行测试,我建议严格遵循 open-mmlab 的基本范式,使用额外的配置文件进行测试。以下是步骤:

  1. 在您的测试配置文件目录中,即,创建一个名为(或您选择的任何其他名称)的新文件夹。在 中创建一个新的配置文件。下面是一个示例(对于 SBD,内容取自从第 56 行开始的函数):work_dirs/interformer_tiny_coco_lvis_320k``intertest_sbd``intertest_sbd``config.py``set_test_cfg``clicktest.py
_base_ = ['../interformer_tiny_coco_lvis_320k.py']  # Note: This must point to your previous test configuration file

pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadSBDAnnotations'),
    dict(
        type='Resize',
        img_scale=None,
        ratio_range=(1.0, 1.0),
        keep_ratio=True),
    dict(type='RandomFlip', prob=0.0),
    dict(
        type='Normalize',
        mean=[123.675, 116.28, 103.53],
        std=[58.395, 57.12, 57.375],
        to_rgb=True),
    dict(
        type='Pad',
        size=None,
        size_divisor=32,
        pad_val=0,
        seg_pad_val=0),
    dict(
        type='ObjectSampler',
        num_samples=1,
        max_num_merged_objects=1,
        min_area_ratio=0.0),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=('img', 'gt_semantic_seg'))
]

data = dict(
    test=dict(
        type=dataset,
        data_root='data/sbd/benchmark_RELEASE/dataset',
        pipeline=pipeline
))

model = dict(
    test_cfg=dict(
        num_clicks=20,
        inner_radius=5,
        outer_radius=0
))
  1. 注释掉 clicktest.py 中的第 178 行,即 。这是因为上面的配置已经实现了这部分,以防止覆盖。cfg = set_test_cfg(cfg, args)
  2. 用于在 intertest_sbd 文件夹中(即与 位于同一目录中)创建指向下载的权重文件的符号链接,然后启动 test 命令。确保将路径更改为 。另请注意,使用 时,源路径必须是绝对路径。ln -s src_file tar_file``iter_320000.pth``config.py``intertest_sbd``ln -s
  3. 最后,请注意,您可以参考 中的函数来调整此示例以测试其他数据集。set_test_cfg``clicktest.py

Hi author, I didn't understand step 3 completely, can you give more detailed instructions on how to do it?

YouHuang67 commented 1 year ago

Sorry for the confusion. In step 3, you can directly copy iter_320000.pth into the new intertest_sbd directory. The use of ln -s is to create a symbolic link, serving the same purpose as copy without actually duplicating the file iter_320000.pth. Indeed, clicktest.py requires an input of the weight file to be tested, in this case iter_320000.pth, and will automatically load a .py configuration file located in the same directory. Please ensure there is only one .py file in this directory.