【问题标题】:How can I convert my imported model to a sequential model?如何将导入的模型转换为顺序模型?
【发布时间】:2019-10-16 10:24:46
【问题描述】:

我有一个类型为 'keras.engine.training.Model' 的导入模型,我想要一个顺序模型。

我试过这个:

model = ..imported model..
seq_model = Sequential()
for layer in model.layers:
    seq_model.add(layer)

但它说“ValueError:应在输入列表上调用合并层。”

【问题讨论】:

  • 为什么需要顺序模型?请注意,如果模型具有非序列结构,则不能将其转换为序列
  • 我想在这个导入的模型中使用 fit_generator。但是当第一个 epoch 结束时,它停止并且不做任何事情。我读到模型类型应该是问题所在(它应该是顺序的)但是当我尝试转换模型时,我收到了上面的错误消息。
  • 不,这是不正确的,fit_generator 在功能模型中工作正常,我每天都在使用它。

标签: python tensorflow keras


【解决方案1】:

如果您尝试插入 ResNet,请检查functional API 以将其用作输出层。

但是,例如:如果您使用的是 VGG16,请查看this

【讨论】:

  • 实际上,我尝试使用 EfficientNet 导入,但在 VGG16 链接中,我不清楚如何在我的代码中使用它。
  • 我的意思是Sequential(layers=functional_model.layers) 这部分并检查您的模型是否如该问题所述变大。如果是这样,您可以利用该问题中的答案。
  • 我试过了,但我得到了同样的错误:“ValueError: A merge layer should be called on a list of inputs.”
猜你喜欢
  • 2020-05-10
  • 1970-01-01
  • 2020-07-22
  • 2017-10-01
  • 1970-01-01
  • 2020-08-25
  • 2019-05-06
  • 2020-08-25
  • 2019-06-28
相关资源
最近更新 更多