MCPcopy Create free account
hub / github.com/pytorch/tutorials / gram_matrix

Function gram_matrix

advanced_source/neural_style_tutorial.py:217–228  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

215#
216
217def 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######################################################################

Callers 2

__init__Method · 0.85
forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected