-
-
Save RaphaelMeudec/18c560ff875cfbe32cc0ff38d3374f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import keras.backend as K | |
from keras.applications.vgg16 import VGG16 | |
from keras.models import Model | |
image_shape = (256, 256, 3) | |
def perceptual_loss(y_true, y_pred): | |
vgg = VGG16(include_top=False, weights='imagenet', input_shape=image_shape) | |
loss_model = Model(inputs=vgg.input, outputs=vgg.get_layer('block3_conv3').output) | |
loss_model.trainable = False | |
return K.mean(K.square(loss_model(y_true) - loss_model(y_pred))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment