(img)
| 28 | |
| 29 | |
| 30 | def 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 | |
| 42 | def style_loss(y, t): |