# 卷积神经网络week4笔记

xiaoxiao2021-03-01  7

### 4. Triplet loss

（末尾小加号表示max（x，0））

### 6.神经风格迁移

# GRADED FUNCTION: compute_layer_style_cost def compute_layer_style_cost(a_S, a_G): """ Arguments: a_S -- tensor of dimension (1, n_H, n_W, n_C), hidden layer activations representing style of the image S a_G -- tensor of dimension (1, n_H, n_W, n_C), hidden layer activations representing style of the image G Returns: J_style_layer -- tensor representing a scalar value, style cost defined above by equation (2) """ ### START CODE HERE ### # Retrieve dimensions from a_G (≈1 line) m, n_H, n_W, n_C = a_G.get_shape().as_list() # Reshape the images to have them of shape (n_H*n_W, n_C) (≈2 lines) a_S = tf.reshape(a_S, [n_H * n_W, n_C]) a_G = tf.reshape(a_G, [n_H * n_W, n_C]) # Computing gram_matrices for both images S and G (≈2 lines) GS = gram_matrix(tf.transpose(a_S)) GG = gram_matrix(tf.transpose(a_G)) # Computing the loss (≈1 line) J_style_layer = (1/(4 * n_C * n_C * n_H * n_W * n_H * n_W))*tf.reduce_sum(tf.square(tf.subtract(GS, GG))) ### END CODE HERE ### return J_style_layer