LSTM\uu call\uuu initial\u state参数有问题

2024-04-19 14:34:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一段代码:

s = Input(shape=(self.s_length,), name="s")
z = Input(shape=(self.z_length,), name="z")
decoder_inputs = [s, z]

# latent.shape: (None, self.s_length + self.z_length)
latent = Concatenate(name="latent_concat")([s, z])

# get initial state of high decoder
# init_state.shape: (None, X_high_size)
init_state = Dense(X_high_size, activation="tanh", name="hidden_state_init")(latent)

# high decoder produces embeddings
# h_X.shape: (None, n_embeddings, self.s_length + self.z_length)
h_X = RepeatVector(n_embeddings, name="latent_repeat")(latent)
for l in range(X_high_depth):
    h_X = LSTM(
        X_high_size,
        return_sequences=True,
        activation="relu",
        name=f"high_encoder_{l}"
    )(h_X, initial_state=[init_state, init_state])

当我运行它时,在训练期间,我得到错误:

File "/home/xxx/anaconda3/envs/mygan/lib/python3.6/site-packages/keras/engine/training.py", line 1215, in train_on_batch
    outputs = self.train_function(ins)
  File "/home/xxx/anaconda3/envs/mygan/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2666, in __call__
    return self._call(inputs)
  File "/home/xxx/anaconda3/envs/mygan/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2636, in _call
    fetched = self._callable_fn(*array_vals)
  File "/home/xxx/anaconda3/envs/mygan/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1382, in __call__
    run_metadata_ptr)
  File "/home/xxx/anaconda3/envs/mygan/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 's' with dtype float and shape [?,16]
     [[Node: s = Placeholder[dtype=DT_FLOAT, shape=[?,16], _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]
     [[Node: loss_2/z_discriminator_loss/Mean_3/_1073 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_41285_loss_2/z_discriminator_loss/Mean_3", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

(顺便说一下,16是输入的s维度。) 但是我注意到,如果我从LSTM层调用中省略initial_state=[init_state, init_state]参数,那么一切都会顺利运行。 代码对我来说似乎是正确的,我不知道我做错了什么…可能是Keras bug?你知道吗


Tags: nameinselfhomeinitdevicelengthfile
1条回答
网友
1楼 · 发布于 2024-04-19 14:34:17

占位符是一个空的输入张量,在拟合或预测时期望接收数据。 如果您指定“初始状态”,LSTM需要实际数据、实数,而当您调用它们时,占位符仍然没有填充。你知道吗

相关问题 更多 >