-
Notifications
You must be signed in to change notification settings - Fork 45.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MNIST Example Keras Model Error #3755
Comments
The API you are trying to use is only available as of TF 1.7. As of TF 1.6, the Keras Model constructor does not allow model subclassing. Please upgrade to the latest TF 1.7 release candidate to fix your issue.
That has been the convention so far, but with the introduction of eager execution, we are adding a new way to use the Keras Model API: model subclassing (as seen in all eager execution code examples). This new API will become part of the Keras API spec in the future, and you will be able to use it with multi-backend Keras too (not just tf.keras). Note that the model subclassing API is available whether or not eager execution is enabled. You can build Models via subclassing even when manipulating symbolic tensors. In general all Model APIs work the same way with or without eager execution. Also note that this new API does not replace any existing API (e.g. |
To add to what fchollet said: The branches in this models repository are compatible with the corresponding branch of the github.com/tensorflow/tensorflow repository. So, if you're looking at the "master" branch here, then you'll need to build TensorFlow from source of the "master" branch. And if you're looking for official samples compatible with a specific version of TensorFlow, look at the corresponding branch (e.g., r1.6, r1.7 etc.) of this repository (See also #3491) Hope that helps. And also, for MNIST in particular, it probably makes sense to switch to |
I have built a model by subclassing Model but I am facing the following bug: `
` |
This Issue documents what I believe to be an error in the MNIST example code.
I was using the code in models/official/mnist/mnist.py as a template for developing a different model, and I ran into an error that I believe exists in the MNIST model code. The following description is when I try to execute code directly copy-pasted from mnist.py.
System information
Describe the problem
The model architecture specification in mnist.py is encapsulated using a
tf.keras.Model
object. The model layers are specified in the__init__()
function, and they are chained together to compute the model's output in the__call__()
function. From what I can tell, the subclassing oftf.keras.Model
is a misuse of the Keras Model class API, and this is not a valid way to construct a model in TensorFlow r1.6.On line 52 of mnist.py, a call is made
super(Model, self).__init__()
. This calls thetf.keras.Model
constructor. However, the Keras Model constructor requires two arguments --inputs
andoutputs
. Thus, when I try to instantiate the Model object, I get the following error:The workaround is not difficult -- one just has to add a
tf.keras.layers.Input
in the__init__()
function, and move the contents of__call__()
into__init__()
. The call tosuper()
should then be moved to the end of__init__()
, to becomewhere
inputs
is thetf.keras.layers.Input
, andoutputs
is the output of the layer representing the model output.That said, as I mentioned, the Keras documentation suggests that Model objects should be instantiated using
Model(inputs, outputs)
rather than trying to subclasstf.keras.Model
as is done in mnist.py (Model class API, Getting started with the Keras functional API).Is my assessment here correct, or am I missing something in the MNIST example code? I'm using TensorFlow version 1.6.0 with Python 2.7.13 (using Anaconda).
The text was updated successfully, but these errors were encountered: