MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / visualize

Function visualize

tools/visualization.py:256–353  ·  view source on GitHub ↗

Perform layer weights and activations visualization on the model. Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py

(cfg)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

plot_evalMethod · 0.95
closeMethod · 0.95
build_modelFunction · 0.90
run_visualizationFunction · 0.85

Tested by

no test coverage detected