1

好吧,我正在使用 AI Platform 在 GCP 上部署基于 LSTM 的 tensorflow 模型。我已经在本地机器上训练和测试了模型。模型如下:

lookback = 16
lstm_input = Input(shape=(1, look_back), name='lstm_input')
x = LSTM(250, name='lstm_0')(lstm_input)
...
x = Dense(1, name='dense_3')(x)

该模型旨在根据之前的 16 个值一次预测一个值。但在实践中,我确实需要 16 个值作为预测。我通过在原始值的末尾附加预测值,然后再次执行预测,直到我有 16 个值如下:

def predict(num_prediction, model):
    prediction_list = list(total_data.iloc[-look_back-1:])

    for _ in range(num_prediction):
        x = np.array(prediction_list[-look_back:])
        x = x.reshape((1, 1, look_back)) #(152, 1, 15)
        out = model.predict(x)
        prediction_list.append(out)
    prediction_list = prediction_list[look_back-1:]

    return prediction_list

另外,我还在本地对数据进行了规范化,并在训练和预测时提供了平均值和标准值。我已将它们导出到一个 json 文件,并将其与我的模型 (.pb) 文件一起上传到 GCP

所以一切都在本地工作。但是我无法在 GCP 上执行此操作,因为我不确定如何使用自己的参数进行非规范化并进行类似的递归预测。我正在尝试使用自定义预测例程来完成该任务,但是一旦将模型部署在那里作为预测,即使是简单的预测也不起作用。因为我已经按照此处的指导完美地格式化了我的输入:

{"instances":[ [[[-1.11942447, -1.22374662, -0.46512613,  2.32171842,
          0.93306964,  0.71291355,  1.74912453,  1.2969071 ,
          0.18740628,  1.20175769,  1.08269237,  0.29160862,
          0.84450949,  2.34316635,  1.11384735,  0.65933734]]] ]}

但它在预测时会引发以下错误:

{
  "error": "Prediction failed: Error during model execution: <_MultiThreadedRendezvous of RPC that terminated with:\n\tstatus = StatusCode.INVALID_ARGUMENT\n\tdetails = \"transpose expects a vector of size 4. But input(1) is a vector of size 3\n\t [[{{node model_4/lstm_0/transpose}}]]\"\n\tdebug_error_string = \"{\"created\":\"@1587901568.938325490\",\"description\":\"Error received from peer ipv4:127.0.0.1:8081\",\"file\":\"src/core/lib/surface/call.cc\",\"file_line\":1056,\"grpc_message\":\"transpose expects a vector of size 4. But input(1) is a vector of size 3\\n\\t [[{{node model_4/lstm_0/transpose}}]]\",\"grpc_status\":3}\"\n>"
}

所以这似乎是一个形状问题,我可能不得不增加尺寸,但添加另一对括号只会使事情变得更糟,并出现以下错误:

{
  "error": "Prediction failed: Error during model execution: <_MultiThreadedRendezvous of RPC that terminated with:\n\tstatus = StatusCode.INVALID_ARGUMENT\n\tdetails = \"transpose expects a vector of size 5. But input(1) is a vector of size 3\n\t [[{{node model_4/lstm_0/transpose}}]]\"\n\tdebug_error_string = \"{\"created\":\"@1588177916.982978933\",\"description\":\"Error received from peer ipv4:127.0.0.1:8081\",\"file\":\"src/core/lib/surface/call.cc\",\"file_line\":1056,\"grpc_message\":\"transpose expects a vector of size 5. But input(1) is a vector of size 3\\n\\t [[{{node model_4/lstm_0/transpose}}]]\",\"grpc_status\":3}\"\n>"
} 

更新 1:现在可以通过只给它 3 个括号来预测单个值。那行得通。但仍在与递归预测和非规范化作斗争。

4

0 回答 0