How to chang the output of the concrete function in Tensorflow 2.x?
I have trained a TensorFlow model and saved it to a local disk. when I loaded it and do inference, how can I get the output of the intermediate layer?
I use the example in the tutorial as a demo.
The model is:

class MyModel(Model):
  def __init__(self):
    super(MyModel, self).__init__()
    self.conv1 = Conv2D(32, 3, activation='relu')
    self.flatten = Flatten()
    self.d1 = Dense(128, activation='relu')
    self.d2 = Dense(10)

  def call(self, x):
    x = self.conv1(x)
    x = self.flatten(x)
    x = self.d1(x)
    return self.d2(x)

# Create an instance of the model
model = MyModel()

I save the model to local and load it in another place.
# save model to local
tf.saved_model.save(model, export_dir=&quot;./saved_model&quot;)

# load model from local
loaded = tf.saved_model.load(&quot;./saved_model&quot;)
concrete_fun = loaded.signatures[&quot;serving_default&quot;]
# do reference
out = concrete_fun(tf.zeros((2, 28, 28, 1)))
out[&quot;output_1&quot;].shape

As I know, the concrete function is unique to the input and output.
How can I get the output, weights and bias of intermediate layers, for example self.conv1?

You can try running:
print([var for var in concrete_fun.trainable_variables])

to get your each layer's weights and biases. To access the graph of your model, you can run concrete_fun.graph. See here for more details.
To access the output of intermediate layers, it would be easiest to save the model like this:
model.save('your_model', save_format='tf')

and then load it:
model.save('your_model', save_format='tf')
model = tf.keras.models.load_model('your_model')
conv_layer = model.get_layer(index=0)
print(conv_layer(tf.random.normal((1, 28, 28, 1))).shape)

