openmedlab / USFM

203 stars 12 forks source link

hydra.errors.MissingConfigException: In 'train.yaml': Could not find 'data/' #9

Open JV-X opened 5 months ago

JV-X commented 5 months ago

I followed README.md to create a local USFM environment, downloaded "USFMlatest.pth" and then executed `python usfm/train.py tag=seg$dataset experiment=ftSeg.yaml model.net.backbone.pretrained=assets/USFM_latest.pth data= $dataset data="{batch_size:40, num_workers:4}" trainer="{devices:[0,1], strategy:ddp}"` , get the error message is as follows:


[2024-04-22 11:07:07,278][usfm.utils.utils][INFO] - Enforcing tags! <cfg.extras.enforce_tags=True>
[2024-04-22 11:07:07,281][usfm.utils.utils][INFO] - Printing config tree with Rich! <cfg.extras.print_config=True>
CONFIG
├── data
│   └── _target_: usfm.data.DS_Segdatamodule.DSSegVocModule
│       data_path:
│         data_root: data/tn3k/
│         data_split:
│           train: train
│           val: val
│           test: test
│           vis:
│             samples: 16
│             interval: 10
│         image_type: jpg
│       transform: null
│       data_DS_path: data
│       batch_size: 40
│       num_workers: 4
│
├── model
│   └── norm_cfg:
│         type: SyncBN
│         requires_grad: true
│       net:
│         type: EncoderDecoder
│         pretrained: null
│         backbone:
│           type: BEiTBackbone4Seg
│           pretrained: assets/USFM_latest.pth
│           img_size: 512
│           patch_size: 16
│           embed_dim: 768
│           depth: 12
│           num_heads: 12
│           mlp_ratio: 4
│           qkv_bias: true
│           use_abs_pos_emb: false
│           use_rel_pos_bias: true
│           init_values: 0.1
│           drop_path_rate: 0.1
│           out_indices:
│           - 3
│           - 5
│           - 7
│           - 11
│         decode_head:
│           type: UPerHead
│           in_channels:
│           - 768
│           - 768
│           - 768
│           - 768
│           in_index:
│           - 0
│           - 1
│           - 2
│           - 3
│           pool_scales:
│           - 1
│           - 2
│           - 3
│           - 6
│           channels: 768
│           dropout_ratio: 0.1
│           num_classes: 2
│           norm_cfg:
│             type: SyncBN
│             requires_grad: true
│           align_corners: false
│           loss_decode:
│             type: CrossEntropyLoss
│             use_sigmoid: false
│             loss_weight: 1.0
│         auxiliary_head:
│           type: FCNHead
│           in_channels: 768
│           in_index: 2
│           channels: 256
│           num_convs: 1
│           concat_input: false
│           dropout_ratio: 0.1
│           num_classes: 2
│           norm_cfg:
│             type: SyncBN
│             requires_grad: true
│           align_corners: false
│           loss_decode:
│             type: CrossEntropyLoss
│             use_sigmoid: false
│             loss_weight: 0.4
│       _target_: usfm.models.beitSegLit.BeitSegLit
│       optimizer:
│         opt: adamW
│         lr: 3.0e-05
│         weight_decay: 0.05
│         opt_betas:
│         - 0.9
│         - 0.999
│         momentum: 0.9
│       scheduler:
│         _target_: torch.optim.lr_scheduler.CosineAnnealingLR
│         _partial_: true
│         T_max: 50
│         eta_min: 1.0e-05
│       metric_keys:
│       - Dice
│
├── callbacks
│   └── model_checkpoint:
│         _target_: lightning.pytorch.callbacks.ModelCheckpoint
│         dirpath: /home/hygx/code/USFM/logs//BeitSeg/seg_tn3k/2024-04-22_11-07-07/checkpoints
│         filename: epoch_{epoch:03d}
│         monitor: val/Dice
│         verbose: false
│         save_last: true
│         save_top_k: 1
│         mode: max
│         auto_insert_metric_name: false
│         save_weights_only: false
│         every_n_train_steps: null
│         train_time_interval: null
│         every_n_epochs: null
│         save_on_train_epoch_end: null
│       early_stopping: null
│       model_summary:
│         _target_: lightning.pytorch.callbacks.RichModelSummary
│         max_depth: -1
│       rich_progress_bar:
│         _target_: lightning.pytorch.callbacks.RichProgressBar
│       LearningRateMonitor:
│         _target_: lightning.pytorch.callbacks.LearningRateMonitor
│         logging_interval: epoch
│
├── logger
│   └── tensorboard:
│         _target_: lightning.pytorch.loggers.tensorboard.TensorBoardLogger
│         save_dir: /home/hygx/code/USFM/logs//BeitSeg/seg_tn3k/2024-04-22_11-07-07/tensorboard/
│         name: null
│         log_graph: false
│         default_hp_metric: true
│         prefix: ''
│
├── trainer
│   └── _target_: lightning.pytorch.trainer.Trainer
│       default_root_dir: /home/hygx/code/USFM/logs//BeitSeg/seg_tn3k/2024-04-22_11-07-07
│       min_epochs: 1
│       max_epochs: 800
│       accelerator: gpu
│       devices:
│       - 0
│       - 1
│       check_val_every_n_epoch: 10
│       deterministic: false
│       gradient_clip_val: 3.0
│       precision: 16-mixed
│       enable_model_summary: false
│       strategy: ddp
│
├── paths
│   └── root_dir: /home/hygx/code/USFM
│       data_dir: /home/hygx/code/USFM/data/
│       log_dir: /home/hygx/code/USFM/logs/
│       output_dir: /home/hygx/code/USFM/logs//BeitSeg/seg_tn3k/2024-04-22_11-07-07
│       work_dir: /home/hygx/code/USFM
│
├── extras
│   └── ignore_warnings: false
│       enforce_tags: true
│       print_config: true
│
├── task_name
│   └── BeitSeg
├── tags
│   └── ['dev']
├── train
│   └── True
├── test
│   └── False
├── compile
│   └── False
├── ckpt_path
│   └── None
├── seed
│   └── 520
├── detail
│   └── beitBaseline
└── tag
    └── seg_tn3k
Seed set to 520
[2024-04-22 11:07:07,322][__main__][INFO] - Instantiating datamodule <usfm.data.DS_Segdatamodule.DSSegVocModule>
[2024-04-22 11:07:08,277][__main__][INFO] - Instantiating model <usfm.models.beitSegLit.BeitSegLit>
[2024-04-22 11:07:08,853][usfm.utils.utils][ERROR] -
Traceback (most recent call last):
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 644, in _locate
    obj = getattr(obj, part)
          ^^^^^^^^^^^^^^^^^^
AttributeError: module 'usfm.models' has no attribute 'beitSegLit'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 650, in _locate
    obj = import_module(mod)
          ^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/hygx/code/USFM/usfm/models/beitSegLit.py", line 14, in <module>
    from usfm.models.components.backbone import beit
  File "/home/hygx/code/USFM/usfm/models/components/backbone/beit.py", line 21, in <module>
    from mmseg.models.builder import BACKBONES
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/models/__init__.py", line 3, in <module>
    from .backbones import *  # noqa: F401,F403
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/models/backbones/__init__.py", line 2, in <module>
    from .beit import BEiT
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/models/backbones/beit.py", line 19, in <module>
    from ..utils import PatchEmbed
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/models/utils/__init__.py", line 2, in <module>
    from .basic_block import BasicBlock, Bottleneck
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/models/utils/basic_block.py", line 10, in <module>
    from mmseg.utils import OptConfigType
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/utils/__init__.py", line 18, in <module>
    from .tokenizer import tokenize
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/mmseg/utils/tokenizer.py", line 14, in <module>
    import regex as re
ModuleNotFoundError: No module named 'regex'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 134, in _resolve_target
    target = _locate(target)
             ^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 653, in _locate
    raise ImportError(
ImportError: Error loading 'usfm.models.beitSegLit.BeitSegLit':
ModuleNotFoundError("No module named 'regex'")
Are you sure that 'beitSegLit' is importable from module 'usfm.models'?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/hygx/code/USFM/usfm/utils/utils.py", line 65, in wrap
    metric_dict, object_dict = task_func(cfg=cfg)
                               ^^^^^^^^^^^^^^^^^^
  File "/home/hygx/code/USFM/usfm/train.py", line 27, in train
    model: LightningModule = hydra.utils.instantiate(cfg.model)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 226, in instantiate
    return instantiate_node(
           ^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 333, in instantiate_node
    _target_ = _resolve_target(node.get(_Keys.TARGET), full_key)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/instantiate/_instantiate2.py", line 139, in _resolve_target
    raise InstantiationException(msg) from e
hydra.errors.InstantiationException: Error locating target 'usfm.models.beitSegLit.BeitSegLit', set env var HYDRA_FULL_ERROR=1 to see chained exception.
full_key: model
[2024-04-22 11:07:08,856][usfm.utils.utils][INFO] - Output dir: /home/hygx/code/USFM/logs//BeitSeg/seg_tn3k/2024-04-22_11-07-07
Error executing job with overrides: ['tag=seg_tn3k', 'experiment=ftSeg.yaml', 'model.net.backbone.pretrained=assets/USFM_latest.pth', 'data=tn3k', 'data={batch_size:40, num_workers:4}', 'trainer={devices:[0,1], strategy:ddp}']
Error locating target 'usfm.models.beitSegLit.BeitSegLit', set env var HYDRA_FULL_ERROR=1 to see chained exception.
full_key: model

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.`

after I set HYDRA_FULL_ERROR = 1 and re-run,I get error as follow:


(USFM) hygx@DESKTOP-47Q8A9V:~/code/USFM$ export HYDRA_FULL_ERROR=1
(USFM) hygx@DESKTOP-47Q8A9V:~/code/USFM$ python usfm/train.py tag=seg_$dataset experiment=ftSeg.yaml model.net.backbone.pretrained=assets/USFM_latest.pth data= $dataset data="{batch_size:40, num_workers:4}" trainer="{devices:[0,1], strategy:ddp}"
Traceback (most recent call last):
  File "/home/hygx/code/USFM/usfm/train.py", line 92, in <module>
    main()
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/main.py", line 94, in decorated_main
    _run_hydra(
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
           ^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
            ^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/hydra.py", line 105, in run
    cfg = self.compose_config(
          ^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/hydra.py", line 594, in compose_config
    cfg = self.config_loader.load_configuration(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/config_loader_impl.py", line 142, in load_configuration
    return self._load_configuration_impl(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/config_loader_impl.py", line 253, in _load_configuration_impl
    defaults_list = create_defaults_list(
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 745, in create_defaults_list
    defaults, tree = _create_defaults_list(
                     ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 715, in _create_defaults_list
    defaults_tree = _create_defaults_tree(
                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 356, in _create_defaults_tree
    ret = _create_defaults_tree_impl(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 457, in _create_defaults_tree_impl
    return _expand_virtual_root(repo, root, overrides, skip_missing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 280, in _expand_virtual_root
    subtree = _create_defaults_tree_impl(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 573, in _create_defaults_tree_impl
    add_child(children, new_root)
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 520, in add_child
    subtree_ = _create_defaults_tree_impl(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 488, in _create_defaults_tree_impl
    config_not_found_error(repo=repo, tree=root)
  File "/home/hygx/anaconda3/envs/USFM/lib/python3.12/site-packages/hydra/_internal/defaults_list.py", line 799, in config_not_found_error
    raise MissingConfigException(
hydra.errors.MissingConfigException: In 'train.yaml': Could not find 'data/'

Available options in 'data':
        tn3k
        tnscui
Config search path:
        provider=hydra, path=pkg://hydra.conf
        provider=main, path=file:///home/hygx/code/USFM/configs
        provider=hydra-colorlog, path=pkg://hydra_plugins.hydra_colorlog.conf
        provider=schema, path=structured://

where did i go wrong? any suggestion?

In addition, when I cloned the code, I did not use git clone https://github.com/George-Jiao/USFM in the document , but git clone https://github.com/openmedlab/USFM.git, because I got repository 'https://github.com/George-Jiao/USFM/' not found error

thanks.

JV-X commented 5 months ago

I run the code on Ubuntu22.04 (WSL2)

pnziy commented 3 months ago

I met the same problem, may i know how did you solve it?

JV-X commented 3 months ago

I met the same problem, may i know how did you solve it?

i'm not solve it yet