如何仅将网络的 3 层应用于数据

数据挖掘 神经网络 深度学习 喀拉斯 张量流 vgg16
2022-02-16 00:26:04

我想使用 VGG16 网络的第 3 层输出。错误如下:

UserWarning: Model inputs must come from `keras.layers.Input` (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to your model was not an Input tensor, it was generated by layer input_1.
Note that input tensors are instantiated via `tensor = keras.layers.Input(shape)`.
The tensor that caused the issue was: input_1:0
  str(x.name))
Traceback (most recent call last):

我正在使用的代码如下:

from keras import Model
from keras import applications

vgg_model = applications.VGG16(include_top=True, weights='imagenet')
vgg_model.summary()
layers = [l for l in vgg_model.layers]

first_layers = layers[0:3]

result_model = Model(input=layers[0].input, output=first_layers[2](first_layers[1](first_layers[0](layers[0].input))))
print("success")
result_model.summary()

我的最终目标是获取此输出并将其发送到另一个进程,它将从第 4 层继续。

我怎样才能像这样将神经网络分成两部分?

0个回答
没有发现任何回复~