'attributeError: 'Tensor' object has no attribute '_keras_history' during implementing perceptual loss with pretrained VGG using keras

我与影子孤独终老i 提交于 2019-12-06 15:54:45

This most of the times means that you're doing calculations outside layers.

A keras model needs to be made of keras layers. Operations outside layers are not allowed.

Take all your calculations and put them inside Lambda layers: https://keras.io/layers/core/#lambda


Here, the mainModel.output[:,frame_num/2] is an operation outside a layer.

Transfer it to a Lambda layer:

lossModel = VGG19(weights='imagenet')
lossModel = Model(inputs=lossModel.input,outputs=lossModel.get_layer('block3_conv4').output)

#you must connect lossmodel and mainmodel somewhere!!!
output = lossModel(mainModel.output)

output = Lambda(lambda x: x[:,frame_num/2])(output)

fullModel = Model(mainModel.input, output)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!