| 215 | # |
| 216 | |
| 217 | def gram_matrix(input): |
| 218 | a, b, c, d = input.size() # a=batch size(=1) |
| 219 | # b=number of feature maps |
| 220 | # (c,d)=dimensions of a f. map (N=c*d) |
| 221 | |
| 222 | features = input.view(a * b, c * d) # resize F_XL into \hat F_XL |
| 223 | |
| 224 | G = torch.mm(features, features.t()) # compute the gram product |
| 225 | |
| 226 | # we 'normalize' the values of the gram matrix |
| 227 | # by dividing by the number of element in each feature maps. |
| 228 | return G.div(a * b * c * d) |
| 229 | |
| 230 | |
| 231 | ###################################################################### |