在形状不兼容的张量上重新调用
Re-called on a Tensor with incompatible shape
我正在尝试通过以下代码在此处创建 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
])
现在的问题是我收到以下警告:
WARNING:tensorflow:Model was constructed with shape
Tensor("dense_12_input:0", shape=(None, None, 7, 7, 1280),
dtype=float32) for input (None, None, 7, 7, 1280), but it was
re-called on a Tensor with incompatible shape (None, 7, 7, 1280).
有谁知道为什么会出现此警告以及我如何应对它,除非它是无害的。
好像是在CNN解决了我的问题后加了一个flatten。因为我们想将一个展平的向量传递给全连接层。该模型应如下所示:
model = keras.Sequential([
cnn_model, keras.layers.Flatten(),
regression_model,
prediction_layer
])
我正在尝试通过以下代码在此处创建 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
])
现在的问题是我收到以下警告:
WARNING:tensorflow:Model was constructed with shape Tensor("dense_12_input:0", shape=(None, None, 7, 7, 1280), dtype=float32) for input (None, None, 7, 7, 1280), but it was re-called on a Tensor with incompatible shape (None, 7, 7, 1280).
有谁知道为什么会出现此警告以及我如何应对它,除非它是无害的。
好像是在CNN解决了我的问题后加了一个flatten。因为我们想将一个展平的向量传递给全连接层。该模型应如下所示:
model = keras.Sequential([
cnn_model, keras.layers.Flatten(),
regression_model,
prediction_layer
])