LSTMで時系列予測をする際に、stateful=Trueを指定し、batch_input_shapeを指定したのですが下記の様なエラーになってしまい、解決方法がわかりません。
Keras Documentation
KerasのステートレスLSTMとステートフルLSTMの違いについて
を参考にしました。
解決策や原因が分かる方いらっしゃいましたら、アドバイスをお願いします。
python
1batch_input_shape=(batch_size, train_steps, np_data.shape[-1]) 2batch_input_shape 3>>>(64, 123, 25) 4 5model = Sequential() 6model.add(layers.LSTM(hl1, 7 recurrent_dropout=recurrent_dropout1, 8 return_sequences=True, 9 stateful=True, 10 batch_input_shape=batch_input_shape)) 11 12model.add(layers.LSTM(hl2, 13 recurrent_dropout=recurrent_dropout2, 14 return_sequences=False, 15 stateful=True)) 16 17model.add(layers.Dense(1))
error
1--------------------------------------------------------------------------- 2RuntimeError Traceback (most recent call last) 3<ipython-input-243-a1221c150bf4> in <module> 4 4 return_sequences=True, 5 5 stateful=True, 6----> 6 batch_input_shape=batch_input_shape)) 7 7 8 8 model.add(layers.LSTM(hl2, 9 10/usr/local/lib/python3.6/dist-packages/keras/engine/sequential.py in add(self, layer) 11 164 # and create the node connecting the current layer 12 165 # to the input layer we just created. 13--> 166 layer(x) 14 167 set_inputs = True 15 168 else: 16 17/usr/local/lib/python3.6/dist-packages/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs) 18 539 19 540 if initial_state is None and constants is None: 20--> 541 return super(RNN, self).__call__(inputs, **kwargs) 21 542 22 543 # If any of `initial_state` or `constants` are specified and are Keras 23 24/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs) 25 487 # Actually call the layer, 26 488 # collecting output(s), mask(s), and shape(s). 27--> 489 output = self.call(inputs, **kwargs) 28 490 output_mask = self.compute_mask(inputs, previous_mask) 29 491 30 31/usr/local/lib/python3.6/dist-packages/keras/layers/recurrent.py in call(self, inputs, mask, training, initial_state) 32 2245 mask=mask, 33 2246 training=training, 34-> 2247 initial_state=initial_state) 35 2248 36 2249 @property 37 38/usr/local/lib/python3.6/dist-packages/keras/layers/recurrent.py in call(self, inputs, mask, training, initial_state, constants) 39 680 mask=mask, 40 681 unroll=self.unroll, 41--> 682 input_length=timesteps) 42 683 if self.stateful: 43 684 updates = [] 44 45/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in rnn(step_function, inputs, initial_states, go_backwards, mask, constants, unroll, input_length) 46 3101 constants=constants, 47 3102 unroll=unroll, 48-> 3103 input_length=input_length) 49 3104 reachable = tf_utils.get_reachable_from_inputs([learning_phase()], 50 3105 targets=[last_output]) 51 52/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/backend.py in rnn(step_function, inputs, initial_states, go_backwards, mask, constants, unroll, input_length, time_major, zero_output_for_mask) 53 3929 # the value is discarded. 54 3930 output_time_zero, _ = step_function( 55-> 3931 input_time_zero, tuple(initial_states) + tuple(constants)) 56 3932 output_ta = tuple( 57 3933 tensor_array_ops.TensorArray( 58 59/usr/local/lib/python3.6/dist-packages/keras/layers/recurrent.py in step(inputs, states) 60 671 else: 61 672 def step(inputs, states): 62--> 673 return self.cell.call(inputs, states, **kwargs) 63 674 64 675 last_output, outputs, states = K.rnn(step, 65 66/usr/local/lib/python3.6/dist-packages/keras/layers/recurrent.py in call(self, inputs, states, training) 67 2035 z = K.dot(inputs, self.kernel) 68 2036 if 0. < self.recurrent_dropout < 1.: 69-> 2037 h_tm1 *= rec_dp_mask[0] 70 2038 z += K.dot(h_tm1, self.recurrent_kernel) 71 2039 if self.use_bias: 72 73/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py in __imul__(self, unused_other) 74 1227 75 1228 def __imul__(self, unused_other): 76-> 1229 raise RuntimeError("Variable *= value not supported. Use " 77 1230 "`var.assign(var * value)` to modify the variable or " 78 1231 "`var = var * value` to get a new Tensor object.") 79 80RuntimeError: Variable *= value not supported. Use `var.assign(var * value)` to modify the variable or `var = var * value` to get a new Tensor object. 81
あなたの回答
tips
プレビュー