keras-js icon indicating copy to clipboard operation
keras-js copied to clipboard

Dense layer not preserving second dimension

Open bminixhofer opened this issue 6 years ago • 0 comments

I am trying to run a CTC Model in the browser. In keras, it looks like this:

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
the_input (InputLayer)          (None, 400, 64, 1)   0                                            
__________________________________________________________________________________________________
conv1 (Conv2D)                  (None, 400, 64, 16)  160         the_input[0][0]                  
__________________________________________________________________________________________________
max1 (MaxPooling2D)             (None, 200, 32, 16)  0           conv1[0][0]                      
__________________________________________________________________________________________________
conv2 (Conv2D)                  (None, 200, 32, 16)  2320        max1[0][0]                       
__________________________________________________________________________________________________
max2 (MaxPooling2D)             (None, 100, 16, 16)  0           conv2[0][0]                      
__________________________________________________________________________________________________
reshape (Reshape)               (None, 100, 256)     0           max2[0][0]                       
__________________________________________________________________________________________________
dense1 (Dense)                  (None, 100, 32)      8224        reshape[0][0]                    
__________________________________________________________________________________________________
gru1 (GRU)                      (None, 100, 512)     837120      dense1[0][0]                     
__________________________________________________________________________________________________
gru1_b (GRU)                    (None, 100, 512)     837120      dense1[0][0]                     
__________________________________________________________________________________________________
add_1 (Add)                     (None, 100, 512)     0           gru1[0][0]                       
                                                                 gru1_b[0][0]                     
__________________________________________________________________________________________________
gru2 (GRU)                      (None, 100, 512)     1574400     add_1[0][0]                      
__________________________________________________________________________________________________
gru2_b (GRU)                    (None, 100, 512)     1574400     add_1[0][0]                      
__________________________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 100, 1024)    0           gru2[0][0]                       
                                                                 gru2_b[0][0]                     
__________________________________________________________________________________________________
dense2 (Dense)                  (None, 100, 80)      82000       concatenate_1[0][0]              
__________________________________________________________________________________________________
softmax (Activation)            (None, 100, 80)      0           dense2[0][0]                     
==================================================================================================
Total params: 4,915,744
Trainable params: 4,915,744
Non-trainable params: 0
__________________________________________________________________________________________________

So I would expect to get an output array of size 8000 (100 * 80). However, I get an array of size 80. After looking at the modelLayersMap of the model in the developer console, I found out that the dimension is (100, 256) as expected on reshape but gets cut down to (1, 32) at dense1. Here is the relevant part of the JSON:

kerasjs_issue

As far as I know, it's fairly uncommon to have a dense layer with 2D output, but I need it for this model. It would be great if this could be added!

bminixhofer avatar Jan 06 '18 10:01 bminixhofer