ResNet50() 不显示摘要和抛出错误
ResNet50() not displaying summary and throwing error
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() 中删除调整大小参数,它会无误地显示摘要。为什么?
tf.keras.applications.resnet.ResNet50(input_shape=(224, 224, 3),
include_top=False,
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()
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() 中删除调整大小参数,它会无误地显示摘要。为什么?
tf.keras.applications.resnet.ResNet50(input_shape=(224, 224, 3),
include_top=False,
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()