Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tf.keras.models.model vs tf.keras.model

Is the models redundant in tf.keras API? For some cases, even without using models, the code also runs well.

  1. keras.models.sequential and keras.sequential
  2. tf.keras.models.Model and tf.keras.Model

However, sometimes, models seems to be necessary. For example,
model = keras.models.load_model(), But model = keras.Model does not has .load_model() function. Because .load_model() is defined in tf.keras.Model.

I find it quite confusing and semi-redundant. Could anyone explain what is the point of models, and when it is necessary?

like image 342
Albert G Lieu Avatar asked Sep 05 '25 13:09

Albert G Lieu


1 Answers

This might be a little more intuitive and easier to read (though admittedly it depends on the accuracy of the documentation). Using the TensorFlow documentation, you can click on "view aliases" as I've done here in the below screenshot:

enter image description here

this will show that tf.keras.Model has tf.keras.models.Model as an alias. Therefore, they point to the same thing.

This is with TensorFlow 2.3.0 but should be similar for other prior 2.x versions.

like image 79
ComputerScientist Avatar answered Sep 10 '25 00:09

ComputerScientist