After Flatten() both batch and output shape of a tensor become none
See original GitHub issueIf I use Flatten() using functional API, both batch and output shape become none, where as in Sequential model its print correct output shape. I need both batch and output size later on and I have to use functional api because of my model complexity, is this is a issue of Keras? @fchollet @farizrahman4u @Dref360
`input = Input(batch_shape=[64,224,224,3])
test = Conv2D(96,kernel_size=(11,11),strides=(4,4), activation=‘relu’,name=‘conv1’)(input) print 'b4 flatten shape ', test.get_shape()
test = Flatten()(test)
print 'after flateen shape ',test.get_shape()
alexnet = Sequential()
alexnet.add(InputLayer(batch_input_shape=img_input))
alexnet.add(Conv2D(96, kernel_size=(11, 11), strides=(4, 4),
activation='relu', name='conv1'))
alexnet.add(Flatten())
print 'Sequential model shape ',alexnet.output_shape`
The output I got :
b4 flatten shape (64, 30, 30, 96) after flatten shape (?, ?) Sequential model shape (64, 86400)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:16 (1 by maintainers)
Top Results From Across the Web
keras Flatten giving wrong output shape - Stack Overflow
I am using keras Flatten() layer after a dropout layer whose output shape is (?,35,50). The output of Flatten() is (?,?) whereas it...
Read more >What is tensorflow flatten with Examples? - eduCBA
Flatten() function will be (size of the batch, 12). ... Flatten(set of input, collection of output: name of class = None, scope: name...
Read more >Flatten layer - Keras
Note: If inputs are shaped (batch,) without a feature axis, then flattening adds an extra channel dimension and output shape is (batch, 1)...
Read more >Beginners Guide to Debugging TensorFlow Models - KDnuggets
This is because we are passing the input shape of (28,28) and 1 extra dimension added by TensorFlow for Batch size, so the...
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
My current workaround is to query the shape before
Flatten()
is done this way:Hi, I am using
Keras 2.1.5
and am getting similar issues withFlatten()
andReshape
not behaving as expected. The output of the same commands as above areThe work around suggested in the previous comment doesn’t work. My current workaround is
which outputs