Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-348

Gram Matrix for Style Loss

Problem

Compute the Gram matrix of a feature map for style loss.

features holds one vector per position; entry (i, j) is the mean over positions of features[p][i] * features[p][j]. Return the dim x dim matrix rounded to 4 decimal places.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [[5,7],[7,10]]
case 2
in: [[[1,0],[0,1],[1,1]]]
expected: [[0.6667,0.3333],[0.3333,0.6667]]
case 3
in: [[[2,0,1]]]
expected: [[4,0,2],[0,0,0],[2,0,1]]
Starter codePython
def style_gram_matrix(features):
    # Your code here
    pass

3 test cases · run your code against them in the editor