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

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

ONNX.js 中的 Pytorch LSTM - 未捕獲(承諾中)錯誤:無法識別節點的輸入“”:

ONNX.js 中的 Pytorch LSTM - 未捕獲(承諾中)錯誤:無法識別節點的輸入“”:

慕慕森 2023-12-14 14:11:20
我正在嘗試在瀏覽器中運行 Pytorch LSTM 網絡。但我收到此錯誤:graph.ts:313 Uncaught (in promise) Error: unrecognized input '' for node: LSTM_4    at t.buildGraph (graph.ts:313)    at new t (graph.ts:139)    at Object.from (graph.ts:77)    at t.load (model.ts:25)    at session.ts:85    at t.event (instrument.ts:294)    at e.initialize (session.ts:81)    at e.<anonymous> (session.ts:63)    at onnx.min.js:14    at Object.next (onnx.min.js:14)我該如何解決這個問題?這是我將模型保存到 onnx 的代碼:net = torch.load('trained_model/trained_model.pt')net.eval()with torch.no_grad():    input = torch.tensor([[1,2,3,4,5,6,7,8,9]])    h0, c0 = net.init_hidden(1)    output, (hn, cn) = net.forward(input, (h0,c0))    torch.onnx.export(net, (input, (h0, c0)), 'trained_model/trained_model.onnx',                    input_names=['input', 'h0', 'c0'],                    output_names=['output', 'hn', 'cn'],                    dynamic_axes={'input': {0: 'sequence'}})我將輸入作為唯一的動態軸,因為它是唯一可以改變大小的軸。使用此代碼,模型可以正確保存為trained_model.onnx。它確實給了我一個警告:UserWarning: Exporting a model to ONNX with a batch_size other than 1, with a variable length with LSTM can cause an error when running the ONNX model with a different batch size. Make sure to save the model with a batch size of 1, or define the initial states (h0/c0) as inputs of the model.   warnings.warn("Exporting a model to ONNX with a batch_size other than 1, "這個警告有點令人困惑,因為我使用批量大小 1 導出它:輸入的形狀為 torch.Size([1, 9])h0 的形狀為 torch.Size([2, 1, 256]) - 對應于 (num_lstm_layers, batch_size, hide_dim)c0 也有形狀 torch.Size([2, 1, 256])但由于我確實將 h0/c0 定義為模型的輸入,所以我認為這與問題無關。根據 console.log 語句,無法加載到模型。我應該如何解決這個問題?如果相關的話我正在使用Python 3.8.5、Pytorch 1.6.0、ONNX 1.8.0。
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

對于將來遇到此問題的任何人,我相信我會收到此錯誤,因為即使 ONNX 支持 Pytorch LSTM 網絡,ONNX.js 尚不支持它。

為了解決這個問題,我可以使用一個名為Streamlit的簡單 Web 應用程序框架,而不是在瀏覽器中運行。


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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