Declare batch input shape independently of first layer with Sequential API
See original GitHub issueI know the functional API supports declaring input shape in an Input layer, and then passing that to a Model()
object, but what’s the equivalent for Sequential()
? I’d expect something like this to work:
model = Sequential()
model.add(Input(batch_shape=(batch_size, height, width, channels)))
model.add(Convolutions/RNNs/Dense/Whatever)
model.compile(...)
but it doesn’t.
AttributeError: ‘TensorVariable’ object has no attribute ‘inbound_nodes’
What am I missing? Shouldn’t the API’s work similarly?
I’d even expect something like (my preferred API, because all models always have at least one input, right?):
model = Sequential((batch_size, height, width, channels))
model.add(Convolutions/RNNs/Dense/Whatever)
model.compile(...)
Also, why is it called batch_input_shape
in some layers, and batch_shape
in others? It’s a bit confusing, honestly.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Making new layers and models via subclassing - Keras
A layer encapsulates both a state (the layer's "weights") and a transformation from inputs to outputs (a "call", the layer's forward pass).
Read more >Custom layers | TensorFlow Core
Layer class and implementing: __init__ , where you can do all input-independent initialization; build , where you know the shapes of the input...
Read more >Guide to the Sequential model - Keras Documentation
Specifying the input shape. The model needs to know what input shape it should expect. For this reason, the first layer in a...
Read more >tf.keras.models.Sequential | TensorFlow - API Manual
Input (shape=(10,)) y3 = model(x3) self.assertEqual(len(model.updates), 4) # But if you call the inner BN layer independently, you don't affect # the model's ......
Read more >How to Use the Keras Functional API for Deep Learning
The sequential API allows you to create models layer-by-layer for most problems. It is limited in that it does not allow you to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
InputLayer
or justLayer
.Input
is a function which returns a tensor. You add layers toSequential
models. Not tensorsIts not. All layers take
batch_input_shape
andinput_shape
arguments. There is “input” in the argument names because they specify the shapes of the tensors which will be “input” to the layer.The
Input
function takesbatch_shape
andshape
arguments. No “input” here. Since here the arguments specify the shape of the tensor (placeholder to be more precise) itself. We are simply asking Keras to create a placeholder of a given shape.@farizrahman4u got it right.
Basically
Input
is the equivalent of instantiating anInputLayer
and calling it in one go. Reading the guide “getting started with the functional API” should clear up any questions.