def style_loss(stylecombination) gram_matrix(stylec gram_matrix(combinationchannels size img_height img_width return sum( square( )( (channels * (size * )to these two loss componentsyou add thirdthe total variation losswhich operates on the pixels of the generated combination image it encourages spatial continuity in the generated imagethus avoiding overly pixelated results you can interpret it as regularization loss listing tot al variation loss def total_variation_loss( ) squarex[::img_height :img_width : [: ::img_width :] squarex[::img_height :img_width : [::img_height ::]return sum( pow( )the loss that you minimize is weighted average of these three losses to compute the content lossyou use only one upper layer--the block _conv layer--whereas for the style lossyou use list of layers than spans both low-level and high-level layers you add the total variation loss at the end depending on the style-reference image and content image you're usingyou'll likely want to tune the content_weight coefficient (the contribution of the content loss to the total lossa higher content_weight means the target content will be more recognizable in the generated image listing defining he final loss hat you'll minimize dictionary that maps layer names to activation tensors outputs_dict dict([(layer namelayer outputfor layer in model layers]content_layer 'block _conv style_layers ['block _conv 'layer used for content loss 'block _conv ''block _conv 'layers used for style loss 'block _conv ''block _conv 'total_variation_weight - weights in the weighted average style_weight of the loss components content_weight licensed to