【问题标题】:TensorFlow 2 AttributeError: 'tuple' object has no attribute 'layer'TensorFlow 2 AttributeError:“元组”对象没有属性“层”
【发布时间】:2020-06-23 11:09:41
【问题描述】:

我正在按照教程使用 Keras 预训练模型,但出现此错误:

AttributeError: 'tuple' 对象没有属性 'layer'

我在 Google Colab 上运行我的代码,所以我尝试将 TensorFlow 降级到版本 1.x,但问题没有解决。那么我该如何解决呢?

这是我的代码片段:

resnet = ResNet152V2(
             include_top=False,
             weights="imagenet",
             input_shape=(40,40,3)
)

for layer in resnet.layers:
    layer.trainable = False

x = resnet.output
x = Flatten()(x)
prediction = Dense(4, activation='softmax')(x)

model = Model(inputs=resnet.input, outputs=prediction)

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

【问题讨论】:

    标签: python tensorflow google-colaboratory tensorflow2.0 resnet


    【解决方案1】:

    你导入了哪些依赖项?

    刚才遇到了同样的问题,我通过确保我的依赖关系一致来解决它。请注意,tensorflow.keras 与从 keras 导入不同。

    【讨论】:

      猜你喜欢
      • 2013-06-21
      • 2021-07-30
      • 2013-07-29
      • 2020-08-29
      • 2015-04-22
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多