Return a dummy input for model analysis with batch size 1. The input is used for analyzing the model (counting flops and activations etc.). Args: cfg (CfgNode): configs. Details can be found in slowfast/config/defaults.py use_train_input (bool): if True,
(cfg, use_train_input)
| 76 | |
| 77 | |
| 78 | def _get_model_analysis_input(cfg, use_train_input): |
| 79 | """ |
| 80 | Return a dummy input for model analysis with batch size 1. The input is |
| 81 | used for analyzing the model (counting flops and activations etc.). |
| 82 | Args: |
| 83 | cfg (CfgNode): configs. Details can be found in |
| 84 | slowfast/config/defaults.py |
| 85 | use_train_input (bool): if True, return the input for training. Otherwise, |
| 86 | return the input for testing. |
| 87 | |
| 88 | Returns: |
| 89 | inputs: the input for model analysis. |
| 90 | """ |
| 91 | rgb_dimension = 3 |
| 92 | if use_train_input: |
| 93 | if cfg.TRAIN.DATASET in ["imagenet", "imagenetprefetch"]: |
| 94 | input_tensors = torch.rand( |
| 95 | rgb_dimension, |
| 96 | cfg.DATA.TRAIN_CROP_SIZE, |
| 97 | cfg.DATA.TRAIN_CROP_SIZE, |
| 98 | ) |
| 99 | else: |
| 100 | input_tensors = torch.rand( |
| 101 | rgb_dimension, |
| 102 | cfg.DATA.NUM_FRAMES, |
| 103 | cfg.DATA.TRAIN_CROP_SIZE, |
| 104 | cfg.DATA.TRAIN_CROP_SIZE, |
| 105 | ) |
| 106 | else: |
| 107 | if cfg.TEST.DATASET in ["imagenet", "imagenetprefetch"]: |
| 108 | input_tensors = torch.rand( |
| 109 | rgb_dimension, |
| 110 | cfg.DATA.TEST_CROP_SIZE, |
| 111 | cfg.DATA.TEST_CROP_SIZE, |
| 112 | ) |
| 113 | else: |
| 114 | input_tensors = torch.rand( |
| 115 | rgb_dimension, |
| 116 | cfg.DATA.NUM_FRAMES, |
| 117 | cfg.DATA.TEST_CROP_SIZE, |
| 118 | cfg.DATA.TEST_CROP_SIZE, |
| 119 | ) |
| 120 | model_inputs = pack_pathway_output(cfg, input_tensors) |
| 121 | for i in range(len(model_inputs)): |
| 122 | model_inputs[i] = model_inputs[i].unsqueeze(0) |
| 123 | if cfg.NUM_GPUS: |
| 124 | model_inputs[i] = model_inputs[i].cuda(non_blocking=True) |
| 125 | |
| 126 | # If detection is enabled, count flops for one proposal. |
| 127 | if cfg.DETECTION.ENABLE: |
| 128 | bbox = torch.tensor([[0, 0, 1.0, 0, 1.0]]) |
| 129 | if cfg.NUM_GPUS: |
| 130 | bbox = bbox.cuda() |
| 131 | inputs = (model_inputs, bbox) |
| 132 | else: |
| 133 | inputs = (model_inputs,) |
| 134 | return inputs |
| 135 |
no test coverage detected