1

I'm doing a transfer learning, and notice that there're no difference between:

letterModel = Model(inputs=trained.get_layer('input').output, outputs = output)

and

letterModel = Model(inputs=trained.input, outputs=output)

Is it true? I can't understand how the output of Input layer can be used as input of new model.

1 Answer 1

3

Your assumption seems to be correct. trained.get_layer('input').output and trained.input are equal Tensors. To verify, I loaded a Keras Model object:

>>> import tensorflow as tf
>>> model = tf.keras.models.load_model('model.h5')

1) Getting the first Input Layer from the model and printing its output tensor.

Note: You used model.get_layer( 'input' ) to get the input layer for the model. I have used model.layers[0] for the same purpose.

>>> model.layers[0].output
<tf.Tensor 'input_1:0' shape=(?, 49152) dtype=float32>

2) Likewise, printing the model input tensor.

>>> model.input
[<tf.Tensor 'input_1:0' shape=(?, 49152) dtype=float32>, <tf.Tensor 'input_2:0' shape=(?, 49152) dtype=float32>]

The model printed a list of two Tensors as the model has two Input layers. As you can see the 1st Tensor is equal to the Tensor printed in ( 1 ).

3) We can check this via a Boolean expression.

>>> model.input[0] == model.layers[0].output
True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.