ValueError:没有这样的层:自定义

时间:2019-03-20 11:21:58

标签: resnet

这是我的resnet50代码,运行此代码时出现错误

if model_name == "vgg16":
  base_model = VGG16(weights=weights)
  model = Model(input=base_model.input, output=base_model.get_layer('fc1').output)
  image_size = (224, 224)
elif model_name == "vgg19":
  base_model = VGG19(weights=weights)
  model = Model(input=base_model.input, output=base_model.get_layer('fc1').output)
  image_size = (224, 224)
elif model_name == "resnet50":
  base_model = ResNet50(weights=weights)
  model = Model(input=base_model.input, output=base_model.get_layer('flatten').output)
  image_size = (224, 224)
elif model_name == "inceptionv3":
  base_model = InceptionV3(include_top=include_top, weights=weights, input_tensor=Input(shape=(299,299,3)))
  model = Model(input=base_model.input, output=base_model.get_layer('custom').output)
  image_size = (299, 299)
elif model_name == "inceptionresnetv2":
  base_model = InceptionResNetV2(include_top=include_top, weights=weights, input_tensor=Input(shape=(299,299,3)))
  model = Model(input=base_model.input, output=base_model.get_layer('custom').output)
  image_size = (299, 299)
elif model_name == "mobilenet":
  base_model = MobileNet(include_top=include_top, weights=weights, input_tensor=Input(shape=(224,224,3)), input_shape=(224,224,3))
  model = Model(input=base_model.input, output=base_model.get_layer('custom').output)
  image_size = (224, 224)
elif model_name == "xception":
  base_model = Xception(weights=weights)
  model = Model(input=base_model.input, output=base_model.get_layer('avg_pool').output)
  image_size = (299, 299)
else:
  base_model = None

我也遇到此错误,并且扁平层没有出现:

[状态]开始时间-2019-03-20 16:32


ValueError                                Traceback (most recent call last)
<ipython-input-6-c3009980d5d0> in <module>()
     59 elif model_name == "resnet50":
     60   base_model = ResNet50(weights=weights)
---> 61   model = Model(input=base_model.input, output=base_model.get_layer('flatten').output)
     62   image_size = (224, 224)
~/anaconda3/lib/python3.6/site-packages/keras/engine/network.py in get_layer(self, name, index)
    356                 return layer
    357 
--> 358         raise ValueError('No such layer: ' + name)
    359 
    360     @property

ValueError: No such layer: flatten

我该如何解决?

0 个答案:

没有答案