All problems
Perceptual Loss Across Layers
Problem
Compute a weighted perceptual loss across several feature layers.
For each layer take the mean squared error between the two feature maps and weight it by weights[layer]. Return the sum of the weighted layer losses rounded to 4 decimal places.
Test cases
case 1
in: [[[[1,2]]],[[[1,4]]],[1]]
expected: 2
case 2
in: [[[[1,2]]],[[[1,4]]],[0.5]]
expected: 1
case 3
in: [[[[1,1]],[[2,2]]],[[[1,2]],[[2,4]]],[1,2]]
expected: 4.5
case 4
in: [[[[0]]],[[[0]]],[3]]
expected: 0
Starter codePython
def perceptual_loss(features_a, features_b, weights):
# Your code here
pass4 test cases · run your code against them in the editor