| 108 | |
| 109 | |
| 110 | def count_conv2d(m, x, y): |
| 111 | cin = m.in_channels |
| 112 | cout = m.out_channels |
| 113 | kh, kw = m.kernel_size |
| 114 | out_h = y.size(2) |
| 115 | out_w = y.size(3) |
| 116 | batch_size = x[0].size(0) |
| 117 | |
| 118 | kernel_ops = multiply_adds * kh * kw |
| 119 | bias_ops = 1 if m.bias is not None else 0 |
| 120 | |
| 121 | output_elements = batch_size * out_w * out_h * cout |
| 122 | total_ops = output_elements * kernel_ops * cin // m.groups + bias_ops * output_elements |
| 123 | m.total_ops = torch.Tensor([int(total_ops)]) |
| 124 | |
| 125 | total_params = kh * kw * cin * cout // m.groups + bias_ops * cout |
| 126 | m.total_params = torch.Tensor([int(total_params)]) |
| 127 | |
| 128 | |
| 129 | def count_bn(m, x, y): |