MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / gram_matrix

Function gram_matrix

cnn_class2/style_transfer2.py:30–39  ·  view source on GitHub ↗
(img)

Source from the content-addressed store, hash-verified

28
29
30def gram_matrix(img):
31 # input is (H, W, C) (C = # feature maps)
32 # we first need to convert it to (C, H*W)
33 X = K.batch_flatten(K.permute_dimensions(img, (2, 0, 1)))
34
35 # now, calculate the gram matrix
36 # gram = XX^T / N
37 # the constant is not important since we'll be weighting these
38 G = K.dot(X, K.transpose(X)) / img.get_shape().num_elements()
39 return G
40
41
42def style_loss(y, t):

Callers 1

style_lossFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected