kerasで実装しようとしたんですがよくわからないエラーが出てきました
LSTM層の➡ )(self.a) の部分でエラーが起きてますたぶん
コード class QNetwork : def __init__(self, learning_rate=0.001, statesize=4, action_size=2): self.inputs = Input(shape=(statesize,)) self.a=Dense(6,activation='relu', use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))(self.inputs) self.a=Dense(6,activation='relu', use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',kernel_constraint=max_norm(2.), bias_constraint=max_norm(2.))(self.a) self.a = LSTM(10,activation='relu', stateful=True, recurrent_activation='hard_sigmoid',use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',unit_forget_bias=True,recurrent_initializer='orthogonal',recurrent_regularizer=max_norm(2.5),dropout=0.1,kernel_constraint=max_norm(2.),recurrent_dropout=0.1, implementation=1,return_sequences=False, return_state=False,go_backwards=False, bias_constraint=max_norm(2.),name="lstm")(self.a) ---略ーーーー
エラー --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-24-4c99caf15b22> in <module> 191 statesize=4 #モデルのinput 192 # [4.2]Qネットワークとメモリ、Actorの生成-------------------------------------------------------- --> 193 mainQN = QNetwork(learning_rate=learning_rate,action_size=2) # メインのQネットワーク 194 targetQN = QNetwork(learning_rate=learning_rate,action_size=2) # 価値を計算するQネットワーク 195 # plot_model(mainQN.model, to_file='Qnetwork.png', show_shapes=True) # Qネットワークの可視化 <ipython-input-24-4c99caf15b22> in __init__(self, learning_rate, statesize, action_size) 47 recurrent_activation='hard_sigmoid',use_bias=True,kernel_initializer='he_normal',bias_initializer='zeros',unit_forget_bias=True,recurrent_initializer='orthogonal',recurrent_regularizer=max_norm(2.5),dropout=0.1,kernel_constraint=max_norm(2.),recurrent_dropout=0.1, 48 implementation=1,return_sequences=False, return_state=False,go_backwards=False, ---> 49 bias_constraint=max_norm(2.),name="lstm")(self.a) 50 51 self.v=Dense(6,activation='relu', ~\Anaconda3\lib\site-packages\keras\layers\recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs) 539 540 if initial_state is None and constants is None: --> 541 return super(RNN, self).__call__(inputs, **kwargs) 542 543 # If any of `initial_state` or `constants` are specified and are Keras ~\Anaconda3\lib\site-packages\keras\engine\base_layer.py in __call__(self, inputs, **kwargs) 444 # Raise exceptions in case the input is not compatible 445 # with the input_spec specified in the layer constructor. --> 446 self.assert_input_compatibility(inputs) 447 448 # Collect input shapes to build layer. ~\Anaconda3\lib\site-packages\keras\engine\base_layer.py in assert_input_compatibility(self, inputs) 340 self.name + ': expected ndim=' + 341 str(spec.ndim) + ', found ndim=' + --> 342 str(K.ndim(x))) 343 if spec.max_ndim is not None: 344 ndim = K.ndim(x) ValueError: Input 0 is incompatible with layer lstm: expected ndim=3, found ndim=2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。