如何解决ResNet50() 不显示摘要并抛出错误
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,weights='imagenet')
解决方法
这是因为您没有通过定义 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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。