"ValueError: The shape of the input to "Flatten" is not fully defined" with variable length LSTM

th4t gi

Here's my code:

    from keras.layers import LSTM, Bidirectional, Dense, Input, Flatten
    from keras.models import Model

    input = Input(shape=(None, 100))
    lstm_out = Bidirectional(LSTM(10, return_sequences=True))(input)
    something = Flatten()(lstm_out)
    output = Dense(22, activation='softmax')(something)

    model = Model(inputs=input, outputs=output)
    model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])

I'm building an LSTM with variable input through this stackoverflow question. But now my model is saying ValueError: The shape of the input to "Flatten" is not fully defined (got (None, 20). How can I fix this?

Thanks in advance

nuric

You can't fix this particular problem because you can pass a variable size vector to a Dense layer. Why? Because it has a fixed size weights matrix, i.e. the kernel W.

You should instead look at layers that can handle variable length sequences such as RNNs. For example you can let the LSTM learn a representation over the entire sequence:

input = Input(shape=(None, 100))
lstm_out = Bidirectional(LSTM(10))(input) # the LSTM produces a single fixed size vector
output = Dense(22, activation='softmax')(lstm_out) # Dense classifies it

If you want more capacity in your model you can chain RNN layers so long as the last one doesn't return sequences:

lstm_out = Bidirectional(LSTM(10, return_sequences=True))(input)
lstm_out = Bidirectional(LSTM(10))(lstm_out) # this LSTM produces a single vector

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Integer array of variable length

分類Dev

Train Keras LSTM model with a variable number of features

分類Dev

Java multiple variable length argument

分類Dev

Retrieve the length of variable argument list

分類Dev

Leading Zeros for Variable Length Field

分類Dev

byte[] array to struct with variable length array

分類Dev

Getting the length of public array variable (getter)

分類Dev

Create empty array with a length from a variable

分類Dev

Variable length substring between two characters

分類Dev

Using Regex to validate a variable length string

分類Dev

R linear regression on a dataframe of variable length

分類Dev

Run time penalty in Variable Length arrays?

分類Dev

How to parse received data with variable length

分類Dev

CEFSharp ExecuteSyncAsync() send variable length parameter array

分類Dev

Evaluate the Maximum Length amongst variable length strings in an one-dimensional Array using Excel VBA

分類Dev

Tensorflow:LSTMのvariable_scopeでの値エラー

分類Dev

Merge multiple lists with variable length "popping" elements from each

分類Dev

Create a dataframe from a dict where values are variable-length lists

分類Dev

Converting a dataframe column containing variable length lists to mutliple columns in dataframe

分類Dev

How to parse variable length command line arguments with regex?

分類Dev

How to combine variable length arguments with keyword arguments in python?

分類Dev

Is there any method for C language to control length of characters by using a variable?

分類Dev

Using ConvertFrom-Csv -Delimiter for variable length whitespace

分類Dev

How can I make a variable-length report using Rmarkdown?

分類Dev

Can I use an integer variable to define an arrays length?

分類Dev

better way to get a list of variable length strings in fortran

分類Dev

Import python dict with variable-length list items into pandas

分類Dev

how to specialize template taking any type to allow variable length arrays

分類Dev

Syntax for Calling a variable-length parameter Scala function from Java?

Related 関連記事

  1. 1

    Integer array of variable length

  2. 2

    Train Keras LSTM model with a variable number of features

  3. 3

    Java multiple variable length argument

  4. 4

    Retrieve the length of variable argument list

  5. 5

    Leading Zeros for Variable Length Field

  6. 6

    byte[] array to struct with variable length array

  7. 7

    Getting the length of public array variable (getter)

  8. 8

    Create empty array with a length from a variable

  9. 9

    Variable length substring between two characters

  10. 10

    Using Regex to validate a variable length string

  11. 11

    R linear regression on a dataframe of variable length

  12. 12

    Run time penalty in Variable Length arrays?

  13. 13

    How to parse received data with variable length

  14. 14

    CEFSharp ExecuteSyncAsync() send variable length parameter array

  15. 15

    Evaluate the Maximum Length amongst variable length strings in an one-dimensional Array using Excel VBA

  16. 16

    Tensorflow:LSTMのvariable_scopeでの値エラー

  17. 17

    Merge multiple lists with variable length "popping" elements from each

  18. 18

    Create a dataframe from a dict where values are variable-length lists

  19. 19

    Converting a dataframe column containing variable length lists to mutliple columns in dataframe

  20. 20

    How to parse variable length command line arguments with regex?

  21. 21

    How to combine variable length arguments with keyword arguments in python?

  22. 22

    Is there any method for C language to control length of characters by using a variable?

  23. 23

    Using ConvertFrom-Csv -Delimiter for variable length whitespace

  24. 24

    How can I make a variable-length report using Rmarkdown?

  25. 25

    Can I use an integer variable to define an arrays length?

  26. 26

    better way to get a list of variable length strings in fortran

  27. 27

    Import python dict with variable-length list items into pandas

  28. 28

    how to specialize template taking any type to allow variable length arrays

  29. 29

    Syntax for Calling a variable-length parameter Scala function from Java?

ホットタグ

アーカイブ