Look at this code (assume Tensorflow 2.1 or 2.2):
import tensorflow as tf
inputs = tf.keras.Input([])
var = tf.Variable(3.0)
out = var*inputs
model = tf.keras.Model(inputs=inputs, outputs=out)
print(model.variables) # prints []
model.saved_vars = tf.Module()
model.saved_vars.var = var
print(model.saved_vars.variables) # prints (<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=3.0>,)
print(model.variables) # prints []
Why is model.variables empy? I would expect to contain var.
As I understant the tf.Module, it works as a namescope and also records tf.Variable assigned to their attributes. Since a tf.keras.Model is a tf.Module, it should do the same recursively, shouldn't it?