FLOPs computation for conv2d op. For conv2d(input,filter): active_elements = batch_size * numel(output) conv_flops = 2 * macs_per_position_conv * active_elements bias_flops = out_channels * active_elements equation: flops = conv_flops + bias_flops
(input_shapes, attrs)
| 72 | |
| 73 | @register_flops("conv2d") |
| 74 | def _conv2d_flops(input_shapes, attrs): |
| 75 | """FLOPs computation for conv2d op. |
| 76 | For conv2d(input,filter): |
| 77 | active_elements = batch_size * numel(output) |
| 78 | conv_flops = 2 * macs_per_position_conv * active_elements |
| 79 | bias_flops = out_channels * active_elements |
| 80 | equation: flops = conv_flops + bias_flops |
| 81 | """ |
| 82 | |
| 83 | bias = ( |
| 84 | input_shapes.get('Bias')[0] |
| 85 | if len(input_shapes.get('Bias')) > 0 |
| 86 | else None |
| 87 | ) |
| 88 | input = input_shapes.get('Input')[0] |
| 89 | weight = input_shapes.get('Filter')[0] |
| 90 | |
| 91 | padding = attrs.get('paddings') |
| 92 | stride = attrs.get('strides') |
| 93 | dilation = attrs.get('dilations') |
| 94 | groups = attrs.get('groups') |
| 95 | |
| 96 | batch_size = input[0] |
| 97 | in_channels = input[1] |
| 98 | out_channels = weight[0] |
| 99 | kernel_dims = list(weight[2:]) |
| 100 | input_dims = list(input[2:]) |
| 101 | length = len(input_dims) |
| 102 | |
| 103 | paddings = ( |
| 104 | padding |
| 105 | if isinstance(padding, list) |
| 106 | else [ |
| 107 | padding, |
| 108 | ] |
| 109 | * length |
| 110 | ) |
| 111 | strides = ( |
| 112 | stride |
| 113 | if isinstance(stride, list) |
| 114 | else [ |
| 115 | stride, |
| 116 | ] |
| 117 | * length |
| 118 | ) |
| 119 | dilations = ( |
| 120 | dilation |
| 121 | if isinstance(dilation, list) |
| 122 | else [ |
| 123 | dilation, |
| 124 | ] |
| 125 | * length |
| 126 | ) |
| 127 | |
| 128 | output_dims = [] |
| 129 | for idx, input_dim in enumerate(input_dims): |
| 130 | output_dim = ( |
| 131 | input_dim |