添加的层必须是类Layer的实例.找到:< tensorflow.python.keras.engine.input_layer.InputLayer> [英] The added layer must be an instance of class Layer. Found: <tensorflow.python.keras.engine.input_layer.InputLayer>

查看:1223
本文介绍了添加的层必须是类Layer的实例.找到:< tensorflow.python.keras.engine.input_layer.InputLayer>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是机器学习的新手.我在微调VGG16模型时遵循了教程.

I am new to machine learning. I was following this tutorial on fine tuning VGG16 models.

此代码可以很好地加载模型:

The model loaded fine with this code:

vgg_model = tensorflow.keras.applications.vgg16.VGG16()

但出现此错误:

TypeError: The added layer must be an instance of class Layer. Found: <tensorflow.python.keras.engine.input_layer.InputLayer object at 0x000001FA104CBB70>

运行此代码时:

model = Sequential()
for layer in vgg_model.layers[:-1]:
    model.add(layer)

依赖项:

  • Keras 2.2.3
  • Tensorflow 1.12.0
  • tensorflow-gpu1.12.0
  • Python 3.6.0

我正在关注博客,但我想使用VGG16.

I am following this blog but instead I want to use VGG16.

任何解决此问题的帮助将不胜感激.非常感谢.

Any help to fix this would be appreciated. Thank you so much.

推荐答案

这将不起作用,因为tensorflow.keras图层已添加到keras模型中.

This won't work because a tensorflow.keras layer is getting added to a keras Model.

vgg_model = tensorflow.keras.applications.vgg16.VGG16()
model = keras.Sequential()
model.add(vgg_model.layers[0])

实例化tensorflow.keras.Sequential().这会起作用.

Instantiate tensorflow.keras.Sequential(). This will work.

model = tensorflow.keras.Sequential()
model.add(vgg_model.layers[0])

这篇关于添加的层必须是类Layer的实例.找到:&lt; tensorflow.python.keras.engine.input_layer.InputLayer&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆