from tensorflow.keras.applications import EfficientNetV2B3
base_model = EfficientNetV2B3(include_top=False, weights="imagenet", input_shape=(224, 224, 3))
print(base_model.output)
<KerasTensor shape=(None, 7, 7, 1536), dtype=float32, sparse=False, name=keras_tensor_411>
my_model = Sequential([
layers.InputLayer(shape=(224, 224, 3)),
layers.Rescaling(scale=1./127.5, offset=-1),
base_model,
layers.GlobalAveragePooling2D(),
layers.Dense(256, activation='relu'),
layers.Dropout(0.4),
layers.Dense(128, activation='relu'),
layers.Dropout(0.4),
layers.Dense(6, activation='softmax')
])
print(my_model.output)
ValueError: The layer sequential has never been called and thus has no defined output.
我在执行以下代码片段时也遇到同样的错误。 我在 Kaggle 中收到此错误,但是当我在 google colab 中执行我的代码时,没有出现此类错误
original_model = load_model('/kaggle/input/models/cifar10.h5') layer_before_softmax_output=original_model.layers[-2].output Layer_before_softmax_model = 模型(输入 = Original_model.input,输出=layer_before_softmax_output)