这是我尝试过的代码,但它给了我 Input 0 is incompatible with layer model_21: expected shape=(None, 224, 224, 3), found shape=(1, 256, 256, 3)
def loss_object(style_outputs, content_outputs, style_target, content_target):
style_weight = 1e-2
content_weight = 1e-1
content_loss = tf.reduce_mean((content_outputs - content_target)**2)
style_loss = tf.add_n([tf.reduce_mean((output_ - target_)**2) for output_, target_ in zip(style_outputs, style_target)])
total_loss = content_weight*content_loss + style_weight*style_loss
return total_loss
vgg_model = load_vgg()
content_target = vgg_model(np.array([content_image*255]))[0]
style_target = vgg_model(np.array([style_image*255]))[1]