【问题标题】:ResNet50() not displaying summary and throwing errorResNet50() 不显示摘要并抛出错误
【发布时间】:2021-04-11 12:42:25
【问题描述】:
inputs = tf.keras.layers.Input(shape=(32,32,3))
resize = tf.keras.layers.UpSampling2D(size=(7,7))(inputs)
feature_extractor = tf.keras.applications.resnet.ResNet50(input_shape=(224, 224,3),include_top=False,weights='imagenet')(resize)
feature_extractor.summary()

上面的代码导致错误AttributeError: 'KerasTensor' object has no attribute 'summary

但是,如果我从 ResNet50() 中删除 resize 参数,如下所示,它会显示摘要而没有错误。为什么?

tf.keras.applications.resnet.ResNet50(input_shape=(224, 224, 3),
                                               include_top=False,
                                               weights='imagenet')

【问题讨论】:

    标签: tensorflow keras transfer-learning


    【解决方案1】:

    这是因为您没有通过定义 tf.keras.models.Model 模型来完成模型的构建。

    inputs = tf.keras.layers.Input(shape=(32,32,3))
    resize = tf.keras.layers.UpSampling2D(size=(7,7))(inputs)
    feature_extractor = tf.keras.applications.resnet.ResNet50(input_shape=(224, 224,3),include_top=False,weights='imagenet')(resize)
    
    model=tf.keras.models.Model(inputs,feature_extractor)
    model.summary()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多