亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為 PyTorch 模型調用 SageMaker 端點

為 PyTorch 模型調用 SageMaker 端點

慕的地8271018 2023-04-25 17:31:10
我正在嘗試從 Postman 和 AWS CLI 調用我的 SageMaker 模型終端節點。端點的狀態是“服務中”,但每當我嘗試調用它時,它都會給我一個錯誤。當我嘗試在 SageMaker notebook 中使用預測函數并為其提供一個 numpy 數組(例如np.array([1,2,3,4]))時,它成功地為我提供了一個輸出。我不確定我做錯了什么。$ aws2 sagemaker-runtime invoke-endpoint \$ --endpoint-name=pytorch-model \$ --body=1,2 \$ --content-type=text/csv \$ --cli-binary-format=raw-in-base64-out \$ output.jsonAn error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "tensors used as indices must be long, byte or bool tensorsTraceback (most recent call last):  File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 125, in transform    result = self._transform_fn(self._model, input_data, content_type, accept)  File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 215, in _default_transform_fn    prediction = self._predict_fn(data, model)  File "/opt/ml/model/code/pytorch-model-reco.py", line 268, in predict_fn    return torch.argsort(- final_matrix[input_data, :], dim = 1)IndexError: tensors used as indices must be long, byte or bool tensors
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

線索在堆棧跟蹤的最后幾行中:


? File "/opt/ml/model/code/pytorch-model-reco.py", line 268, in predict_fn

? ? return torch.argsort(- final_matrix[input_data, :], dim = 1)

IndexError: tensors used as indices must be long, byte or bool tensors

在第 268predict_fn行中pytorch-model-reco.py,您嘗試將 用作input_data的索引final_matrix,但input_data類型錯誤。


我猜想當predict_fn輸入類型為 時,您應該進行一些類型轉換text/csv。當您的輸入類型是 numpy 數據時,這種類型轉換發生在外部predict_fn。


查看完整回答
反對 回復 2023-04-25
  • 1 回答
  • 0 關注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號