2017-03-29 3 views
1

TensorFlow 백엔드가있는 Keras를 사용하여 몇 개의 RNN을 직렬로 스택하려고합니다. 단일 SimpleRNN 레이어가있는 모델을 만들 수 있지만 두 번째 레이어를 추가하려고하면 적절한 입력 크기를 알아낼 수 없습니다.누적 된 RNN의 입력 모양

from keras import models 
from keras.layers.recurrent import SimpleRNN 
from keras.layers import Activation 


model = models.Sequential() 

hidden_units = 256 
skeleton_dimensions = 3 * 16 # 3 dimensions for 16 joints 
input_temporal_length = 7 

in_shape = (input_temporal_length, skeleton_dimensions,) 

# three hidden layers of 256 each 
model.add(SimpleRNN(hidden_units, input_shape=in_shape, 
        activation='relu', use_bias=True,)) 
# what input shape is this supposed to have? 
model.add(SimpleRNN(hidden_units, input_shape=(1, skeleton_dimensions,), 
        activation='relu', use_bias=True,)) 

두 번째 SimpleRNN의 입력 모양은 무엇입니까?

Recurrent Layers의 문서는 암시하는 것 같다

Output shape

  • if return_sequences: 3D tensor with shape (batch_size, timesteps, units).
  • else, 2D tensor with shape (batch_size, units).

을 자동으로 내가 적절하게 다음 차원의 input_shape을 설정하려고 False로 설정되어 return_sequences을 감안할 때,하지만 오류 얻을 :

Using TensorFlow backend. 
Traceback (most recent call last): 
    File "rnn_agony.py", line 19, in <module> 
    activation='relu', use_bias=True,)) 
    File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 455, in add 
    output_tensor = layer(self.outputs[0]) 
    File "/usr/local/lib/python3.5/dist-packages/keras/layers/recurrent.py", line 252, in __call__ 
    return super(Recurrent, self).__call__(inputs, **kwargs) 
    File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 511, in __call__ 
    self.assert_input_compatibility(inputs) 
    File "/usr/local/lib/python3.5/dist-packages/keras/engine/topology.py", line 413, in assert_input_compatibility 
    str(K.ndim(x))) 
ValueError: Input 0 is incompatible with layer simple_rnn_2: expected ndim=3, found ndim=2 

답변

1

RNN을 스태킹하는 경우 input_shape에서 벗어나려면 return_sequences=True을 설정해야합니다. 이는 RNN이 입력 시퀀스를 예상하기 때문에 직관적 인 의미를 갖습니다.