简体   繁体   中英

What's the input_size for the RNN Model in Keras

I'm just starting with deep learning, and I've been told that Keras would be the best library for beginners.

Before that, for the sake of learning, I built a simple feed forward network using only numpy so I could get the feel of it.

In this case, the shape of the weight matrix was (len(X[0]), num_neurons) . The number of features and the number of neurons. And it worked.

Now, I'm trying to build a simple RNN using Keras. My data has 7 features and the size of the layer would be 128.

But if I do something like model.add(Dense(128, input_dim=(7, 128))) it says it's wrong.

So I have no idea what this input_dim should be.

My data has 5330 data points and 7 features (shape is (5330, 7)). Can someone tell me what the input_dim should be and why?

Thank you.

The input_dim is just the shape of the input you pass to this layer. So:

  • input_dim = 7

There are other options, such as:

  • input_shape=(7,) -- This argument uses tuples instead of integers, good when your input has more than one dimension
  • batch_input_shape=(batch_size,7) -- This is not usually necessary, but you use it in cases you need a fixed batch size (there are a few layer configurations that demand that)

Now, the size of the output in a Dense layer is the units argument. Which is 128 in your case and should be equal to num_neurons .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM