I'm using tensorflow 2.7.1 and there I'm trying to define a name for a certain layer in my model like this:
tf.reduce_mean(some_other_tf, axis=1, name='my_name')
Later after compiling the model I want to access this layer by its name using
model.get_layer("my_name")
But it seems like there is no layer with the defined name available, the name of the particular layer is then someting like:
tf.math.reduce_mean_27
In earliert versions of tensoflow this layer was selectable using this:
tf_op_layer_my_name
How can I access such an op layer in tensorflow 2.7.1 by its defined name?
Thanks!
CodePudding user response:
This is because reduce_mean
is not an actual layer, just an op. You can instead use Lambda
to define layers from functions and give them specific names. E.g.
mean_result = tf.keras.layers.Lambda(lambda x: tf.reduce_mean(x, axis=1),
name="some_layer_name")(layer_input)
Now your model should have an layer that is actually named "some_layer_name" and not something else.