对于生成对抗网络的培训我正在使用Perceptual_Loss函数 . Perceptual_Loss是用于在识别图像的特征之后找出两个图像是否彼此相似的函数 . 如上所述here我们可以使用图像分类器和自动编码器来识别特征 . 大多数开发人员使用 VGG16 作为图像分类器来计算Perceptual_Loss . 我想使用预先训练过的自动编码器(我自己训练) . 使用预先训练的自动编码器权重我已将以下原始Perceptual_Loss函数更改为
#### Original Perceptual Loss Function ####
from keras.applications.vgg16 import VGG16
def perceptual_loss(y_true, y_pred):
vgg = VGG16(include_top=False, weights='imagenet', input_shape=(256,256,3))
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)))
#### My Perceptual Loss Function ####
trained_autoencoder=load_model('Path/AutoEncoder_Model.h5')
trained_autoencoder.compile(loss='mean_squared_error', optimizer='adadelta')
def perceptual_loss(y_true, y_pred):
return K.mean(K.square(trained_autoencoder.predict(y_true) - trained_autoencoder.predict(y_pred)))
但它给了我这个错误
**When feeding symbolic tensors to a model, we expect thetensors to have a static batch size. Got tensor with shape: (None, None, None, None)**