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

How to get validation loss using mmdetection version 2.28.2? #11693

Closed
CarolinRue opened this issue May 8, 2024 · 1 comment
Closed

How to get validation loss using mmdetection version 2.28.2? #11693

CarolinRue opened this issue May 8, 2024 · 1 comment
Assignees

Comments

@CarolinRue
Copy link

CarolinRue commented May 8, 2024

Hii, I am new to mmdetection and want to get the validation loss. I found this #505.
I added workflow = [('train', 1), ('val', 1)] but then I get this error

File "tools/train.py", line 247, in <module>
    main()
  File "tools/train.py", line 226, in main
    'pipeline', cfg.data.train.dataset.get('pipeline'))
  File "/home/mm/miniconda3/envs/mmdet/lib/python3.8/site-packages/mmcv/utils/config.py", line 52, in __getattr__
    raise ex
AttributeError: 'ConfigDict' object has no attribute 'dataset'

I am also not sure how to set this "Also you need to modify the data_loaders in this line, your need to append your valset_loader at the end of data_loaders", because in version 2.28.2 the data_loaders looks different. In version 2.28.2 there is no _dist_train function, here it looks like this:

def train_detector(model,
                   dataset,
                   cfg,
                   distributed=False,
                   validate=False,
                   timestamp=None,
                   meta=None):

    cfg = compat_cfg(cfg)
    logger = get_root_logger(log_level=cfg.log_level)

    # prepare data loaders
    dataset = dataset if isinstance(dataset, (list, tuple)) else [dataset]

    runner_type = 'EpochBasedRunner' if 'runner' not in cfg else cfg.runner[
        'type']

    train_dataloader_default_args = dict(
        samples_per_gpu=2,
        workers_per_gpu=2,
        # `num_gpus` will be ignored if distributed
        num_gpus=len(cfg.gpu_ids),
        dist=distributed,
        seed=cfg.seed,
        runner_type=runner_type,
        persistent_workers=False)

    train_loader_cfg = {
        **train_dataloader_default_args,
        **cfg.data.get('train_dataloader', {})
    }

    data_loaders = [build_dataloader(ds, **train_loader_cfg) for ds in dataset]

Can somebody help me to get the validation loss in mmdetection version 2.28.2?

@CarolinRue CarolinRue changed the title How to get validation loss in mmdetection version 2.28.2? How to get validation loss using mmdetection version 2.28.2? May 9, 2024
@CarolinRue
Copy link
Author

Solved: 1. add workflow = [('train', 1), ('val', 1)] in config 2. change line 225/226 in train.py to val_dataset.pipeline = cfg.data.train.get('pipeline', cfg.data.val.get('pipeline'))

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

No branches or pull requests

2 participants