【问题标题】:i have facing this error Input 0 is incompatible with layer model_14: expected shape=(None, 224, 224, 3), found shape=(1, 256, 256, 3)我遇到了这个错误 Input 0 is in compatible with layer model_14: expected shape=(None, 224, 224, 3), found shape=(1, 256, 256, 3)
【发布时间】:2022-01-25 22:22:37
【问题描述】:

这是我尝试过的代码,但它给了我 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]

【问题讨论】:

    标签: python-3.x tensorflow deep-learning generative-adversarial-network stylegan


    【解决方案1】:

    根据错误,您使用的预训练模型期望输入为 shape(None, 224, 224, 3),但您输入的是 shape(1, 256, 256, 3 )。您必须将输入调整为 (224,224) 并将其重新调整为 (None,224,224,3)。要重塑图像,请使用以下类似代码:

    image=image.reshape(None,224,224,3)
    

    如果问题仍然存在,请告诉我们。谢谢!

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 2021-09-03
      • 2022-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多