forked from deepak112/Keras-SRGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils_model.py
36 lines (27 loc) · 1.07 KB
/
Utils_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
#title :Utils_model.py
#description :Have functions to get optimizer and loss
#author :Deepak Birla
#date :2018/10/30
#usage :imported in other files
#python_version :3.5.4
from keras.applications.vgg19 import VGG19
import keras.backend as K
from keras.models import Model
from keras.optimizers import Adam
class VGG_LOSS(object):
def __init__(self, image_shape):
self.image_shape = image_shape
# computes VGG loss or content loss
def vgg_loss(self, y_true, y_pred):
vgg19 = VGG19(include_top=False, weights='imagenet', input_shape=self.image_shape)
vgg19.trainable = False
# Make trainable as False
for l in vgg19.layers:
l.trainable = False
model = Model(inputs=vgg19.input, outputs=vgg19.get_layer('block5_conv4').output)
model.trainable = False
return K.mean(K.square(model(y_true) - model(y_pred)))
def get_optimizer():
adam = Adam(lr=1E-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08)
return adam