Perform layer weights and activations visualization on the model. Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py
(cfg)
| 247 | |
| 248 | |
| 249 | def visualize(cfg): |
| 250 | """ |
| 251 | Perform layer weights and activations visualization on the model. |
| 252 | Args: |
| 253 | cfg (CfgNode): configs. Details can be found in |
| 254 | slowfast/config/defaults.py |
| 255 | """ |
| 256 | if cfg.TENSORBOARD.ENABLE and ( |
| 257 | cfg.TENSORBOARD.MODEL_VIS.ENABLE |
| 258 | or cfg.TENSORBOARD.WRONG_PRED_VIS.ENABLE |
| 259 | ): |
| 260 | # Set up environment. |
| 261 | du.init_distributed_training(cfg) |
| 262 | # Set random seed from configs. |
| 263 | np.random.seed(cfg.RNG_SEED) |
| 264 | torch.manual_seed(cfg.RNG_SEED) |
| 265 | |
| 266 | # Setup logging format. |
| 267 | logging.setup_logging(cfg.OUTPUT_DIR) |
| 268 | |
| 269 | # Print config. |
| 270 | logger.info("Model Visualization with config:") |
| 271 | logger.info(cfg) |
| 272 | |
| 273 | # Build the video model and print model statistics. |
| 274 | model = build_model(cfg) |
| 275 | model.eval() |
| 276 | if du.is_master_proc() and cfg.LOG_MODEL_INFO: |
| 277 | misc.log_model_info(model, cfg, use_train_input=False) |
| 278 | |
| 279 | cu.load_test_checkpoint(cfg, model) |
| 280 | |
| 281 | # Create video testing loaders. |
| 282 | vis_loader = loader.construct_loader(cfg, "test") |
| 283 | |
| 284 | if cfg.DETECTION.ENABLE: |
| 285 | assert cfg.NUM_GPUS == cfg.TEST.BATCH_SIZE or cfg.NUM_GPUS == 0 |
| 286 | |
| 287 | # Set up writer for logging to Tensorboard format. |
| 288 | if du.is_master_proc(cfg.NUM_GPUS * cfg.NUM_SHARDS): |
| 289 | writer = tb.TensorboardWriter(cfg) |
| 290 | else: |
| 291 | writer = None |
| 292 | if cfg.TENSORBOARD.PREDICTIONS_PATH != "": |
| 293 | assert not cfg.DETECTION.ENABLE, "Detection is not supported." |
| 294 | logger.info( |
| 295 | "Visualizing class-level performance from saved results..." |
| 296 | ) |
| 297 | if writer is not None: |
| 298 | with PathManager.open( |
| 299 | cfg.TENSORBOARD.PREDICTIONS_PATH, "rb" |
| 300 | ) as f: |
| 301 | preds, labels = pickle.load(f, encoding="latin1") |
| 302 | |
| 303 | writer.plot_eval(preds, labels) |
| 304 | |
| 305 | if cfg.TENSORBOARD.MODEL_VIS.ENABLE: |
| 306 | if cfg.TENSORBOARD.MODEL_VIS.GRAD_CAM.ENABLE: |
nothing calls this directly
no test coverage detected