| 29 | |
| 30 | |
| 31 | def build_dataset_from_config(cfg, dataset_name): |
| 32 | import vlmeval.dataset |
| 33 | import inspect |
| 34 | config = cp.deepcopy(cfg[dataset_name]) |
| 35 | if config == {}: |
| 36 | return supported_video_datasets[dataset_name]() |
| 37 | assert 'class' in config |
| 38 | cls_name = config.pop('class') |
| 39 | if hasattr(vlmeval.dataset, cls_name): |
| 40 | cls = getattr(vlmeval.dataset, cls_name) |
| 41 | sig = inspect.signature(cls.__init__) |
| 42 | valid_params = {k: v for k, v in config.items() if k in sig.parameters} |
| 43 | if cls.MODALITY == 'VIDEO': |
| 44 | if valid_params.get('fps', 0) > 0 and valid_params.get('nframe', 0) > 0: |
| 45 | raise ValueError('fps and nframe should not be set at the same time') |
| 46 | if valid_params.get('fps', 0) <= 0 and valid_params.get('nframe', 0) <= 0: |
| 47 | raise ValueError('fps and nframe should be set at least one valid value') |
| 48 | return cls(**valid_params) |
| 49 | else: |
| 50 | raise ValueError(f'Class {cls_name} is not supported in `vlmeval.dataset`') |
| 51 | |
| 52 | |
| 53 | |