Why model = Model(pre_trained_model.input, x) would include the layers before 'mixed7'?

Something you should know the last layer output shape being None, 7, 7, 768 cannot be just mixed 7 layer as it is an outcome of input shape, convolution layer and other layers used till mixed 7.

if that line meant only mixed7, then code line before would not have include pre_trained_model.get_layer(mixed7)

these algorithm are stepwise recollection and selection of data to make it specified for the newer model to use how much part of old model it wants to use.

try yourself with your codes by just using last output=last_layer(mixed 7) without using pre_trained model summary, would it give you the same output??

Regards
DP

Thank you DP, this makes some sense. But I still do not fully understand the syntax.

I tried “last_output2 = last_layer(‘mixed7’)”, but got “ValueError: Exception encountered when calling layer ‘mixed7’ (type Concatenate).”

For this code,
last_layer = pre_trained_model.get_layer(‘mixed7’)
can I consider last_layer as a subset of pre_trained_model?
If yes, “last_layer.summary()” also outputs “AttributeError: ‘Concatenate’ object has no attribute ‘summary’”.

@Cheng_Zhang1

Because summary of a layer will always invoke this error. As it doesn’t includes the pre_trained_model

If you are getting this.

The steps involved here are

  1. Using a selective shape from the inception model.
  2. Including a weight from the inception model then
  3. Freezing the layers whose weight won’t be used.

So this actually is giving an overall summary of the old model used which does include all the mixed layer.

Then where the recall last layer function code makes sure mixed7 is the layer till which the old model will be used.

And that is then passed to the new architecture model which would be used to train the newer model

Maybe this analogy would help.

Picture the model as a flow chart, where you have an input at the top, and the output at the bottom, and each block in the flow represents a layer.

By selecting one block, you’re tapping into the state of the model that that layer - but the model still includes all of the previous layers going back to the input.

Thank you both. I agree the code will keep the layers up to mixed7 (because apparently it does).

But I just want to have clearer evidence to prove that. e.g. showing the properties of an object can reflect that the object really carries over the layers information to the next object.

I think we can stop here for now. Thank you for all your support!

ChatGPT told me this, and I think it makes sense to me.

How Layers Before mixed7 Are Included

The magic happens when you create the new model with model = Model(pre_trained_model.input, x). Here’s what happens:

  1. Start with pre_trained_model.input: This is the input layer of the original InceptionV3 model. It represents the starting point where the input images are fed.
  2. End with x: This is the output of your custom layers that you’ve added after the mixed7 layer.

When you create the model this way, TensorFlow automatically understands that it needs to include all operations that lead from pre_trained_model.input to x. This means every layer and operation that happens in the InceptionV3 model from the input layer up to and including mixed7 is included. Then, your custom layers are added on top.

the line model = Model(pre_trained_model.input, x) doesn’t just magically include the layers before mixed7 ; it constructs a new model that starts from the input layer of InceptionV3, processes through all layers up to mixed7 , and then continues through the custom layers you’ve added. This is how the entire model, including both pre-trained and custom layers, is formed and why it includes the layers before mixed7 .

I recommend you use extreme caution when asking a chat tool for programming advice.

2 Likes