【问题标题】:Re-called on a Tensor with incompatible shape重新调用形状不兼容的张量
【发布时间】:2020-05-03 02:26:33
【问题描述】:

我正在尝试通过下面的代码在这里创建一个 CNN + 回归模型:

# Create the base model from the pre-trained model MobileNet V2
cnn_model = keras.applications.MobileNetV2(input_shape=IMG_SHAPE,
                                            include_top=False,
                                            weights='imagenet')

# The Regression Model
regression_model = keras.Sequential([
                        keras.layers.Dense(64, activation='relu', 
                                            input_shape=cnn_model.output_shape),
                        keras.layers.Dense(64, activation='relu')
                    ])

prediction_layer = tf.keras.layers.Dense(1)

# Final Model
model = keras.Sequential([
            cnn_model,
            regression_model,
            prediction_layer
        ])

现在的问题是我收到以下警告:

警告:tensorflow:模型是用形状构造的 张量("dense_12_input:0", shape=(None, None, 7, 7, 1280), dtype=float32) 用于输入(无、无、7、7、1280),但它是 重新调用形状不兼容的张量 (None, 7, 7, 1280)。

有没有人知道为什么会出现这个警告以及我可以如何应对它,除非它是无害的。

【问题讨论】:

    标签: python tensorflow keras tensorflow2.0 tf.keras


    【解决方案1】:

    似乎在 CNN 解决了​​我的问题之后添加了一个扁平化。因为我们想将一个扁平化的向量传递给全连接层。模型应如下所示:

    model = keras.Sequential([
                cnn_model, keras.layers.Flatten(),
                regression_model,
                prediction_layer
            ])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多