Perform multi-view testing on the pretrained video model. Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py
(cfg)
| 141 | |
| 142 | |
| 143 | def test(cfg): |
| 144 | """ |
| 145 | Perform multi-view testing on the pretrained video model. |
| 146 | Args: |
| 147 | cfg (CfgNode): configs. Details can be found in |
| 148 | slowfast/config/defaults.py |
| 149 | """ |
| 150 | # Set up environment. |
| 151 | du.init_distributed_training(cfg) |
| 152 | # Set random seed from configs. |
| 153 | np.random.seed(cfg.RNG_SEED) |
| 154 | torch.manual_seed(cfg.RNG_SEED) |
| 155 | |
| 156 | # Setup logging format. |
| 157 | logging.setup_logging(cfg.OUTPUT_DIR) |
| 158 | |
| 159 | # Print config. |
| 160 | logger.info("Test with config:") |
| 161 | logger.info(cfg) |
| 162 | |
| 163 | # Build the video model and print model statistics. |
| 164 | model = build_model(cfg) |
| 165 | if du.is_master_proc() and cfg.LOG_MODEL_INFO: |
| 166 | misc.log_model_info(model, cfg, use_train_input=False) |
| 167 | |
| 168 | cu.load_test_checkpoint(cfg, model) |
| 169 | |
| 170 | # Create video testing loaders. |
| 171 | test_loader = loader.construct_loader(cfg, "test") |
| 172 | logger.info("Testing model for {} iterations".format(len(test_loader))) |
| 173 | logger.info(f"Add softmax after prediction: {cfg.TEST.ADD_SOFTMAX}") |
| 174 | |
| 175 | if cfg.DETECTION.ENABLE: |
| 176 | assert cfg.NUM_GPUS == cfg.TEST.BATCH_SIZE or cfg.NUM_GPUS == 0 |
| 177 | test_meter = AVAMeter(len(test_loader), cfg, mode="test") |
| 178 | else: |
| 179 | assert ( |
| 180 | test_loader.dataset.num_videos |
| 181 | % (cfg.TEST.NUM_ENSEMBLE_VIEWS * cfg.TEST.NUM_SPATIAL_CROPS) |
| 182 | == 0 |
| 183 | ) |
| 184 | # Create meters for multi-view testing. |
| 185 | test_meter = TestMeter( |
| 186 | test_loader.dataset.num_videos |
| 187 | // (cfg.TEST.NUM_ENSEMBLE_VIEWS * cfg.TEST.NUM_SPATIAL_CROPS), |
| 188 | cfg.TEST.NUM_ENSEMBLE_VIEWS * cfg.TEST.NUM_SPATIAL_CROPS, |
| 189 | cfg.MODEL.NUM_CLASSES, |
| 190 | len(test_loader), |
| 191 | cfg.DATA.MULTI_LABEL, |
| 192 | cfg.DATA.ENSEMBLE_METHOD, |
| 193 | ) |
| 194 | |
| 195 | # Set up writer for logging to Tensorboard format. |
| 196 | if cfg.TENSORBOARD.ENABLE and du.is_master_proc( |
| 197 | cfg.NUM_GPUS * cfg.NUM_SHARDS |
| 198 | ): |
| 199 | writer = tb.TensorboardWriter(cfg) |
| 200 | else: |
nothing calls this directly
no test coverage detected