Reputation: 21
I want to build a CNN from another CNN to extract the featured vector of an image. The idea is only to take the first 13 layers of the first CNN and build the second with these layers.
I'm using a Google Colab Notebook with GPU's
from keras.models import Model
layer_input_f_nmist = model_f_mnist.input
layer_outputs = [layer.output for layer in model_f_mnist.layers[:13]]
model_mnist_featured = Model(inputs = layer_input_f_nmist, outputs = layer_outputs)
featured_f_mnist_train = model_mnist_featured.predict(X_f_mnist_train)
TypeError Traceback (most recent call last)
<ipython-input-74-ceb627fe9c83> in <module>()
4 layer_outputs = [layer.output for layer in model_f_mnist.layers[:13]]
5
----> 6 model_mnist_featured = Model(inputs = layer_input_f_nmist, outputs = layer_outputs)
7
8 featured_f_mnist_train = model_mnist_featured.predict(X_f_mnist_train)
4 frames
/usr/local/lib/python3.6/dist-packages/keras/engine/network.py in build_map(tensor, finished_nodes, nodes_in_progress, layer, node_index, tensor_index)
1400
1401 # Propagate to all previous tensors connected to this node.
-> 1402 for i in range(len(node.inbound_layers)):
1403 x = node.input_tensors[i]
1404 layer = node.inbound_layers[i]
TypeError: object of type 'InputLayer' has no len()
Upvotes: 2
Views: 2346
Reputation: 71
I have had the same problem. I have used tf.keras.layers
to implement the model in google colab. The outputs and inputs of keras.layers arn't match outputs and inputs of tf.keras.layers
. I haven't look background of models. Problem is solved when I use tf.keras.models.Model
(inputs = classifier.input
, outputs = layer_outputs
) instead of Model(inputs = classifier.input
, outputs = layer_outputs
). I suggest to use tf.keras.*
attributes instead of keras.*
when you work with google colab.
Upvotes: 7