Loading Python Exported Model into TorchSharp
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 32/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
調査の方向性
まず docfx/articles/saveload.md と src/Python/exportsd.py を確認し、次に TorchSharpExamples から参照されている ResNet.cs モデルを調査します。Python の state_dict 名と TorchSharp が生成するモジュール名を比較し、ResNet18 の例を使って load() の失敗を再現します。Python からエクスポートした ResNet モデルが、報告されている名前またはシリアライゼーションの例外なしに例で正常に読み込まれれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Originally posted in dotnet/TorchSharp by @jimquittenton:
https://github.com/dotnet/TorchSharp/issues/586
The naming scheme for layers are different in the ResNet example model found in this repo and the ResNet models found in TorchVision, which prevents a model saved from Python from being loaded in TorchSharp using this example code.
Original post:
Hi,
I'm new to TorchSharp and am having trouble loading a python trained ResNet18 model. I've been following this article: https://github.com/dotnet/TorchSharp/blob/main/docfx/articles/saveload.md and have exported my python model using the 'save_state_dict' function in this script: https://github.com/dotnet/TorchSharp/blob/main/src/Python/exportsd.py .
In TorchSharp I have copied the ResNet model from https://github.com/dotnet/TorchSharpExamples/blob/main/src/CSharp/Models/ResNet.cs and then call the following:
int numClasses = 3;
ResNet myModel = ResNet.ResNet18(numClasses);
myModel.to(DeviceType.CPU);
myModel.load(mPath);
The load() line throws an exception with message Mismatched module state names: the target modules does not have a submodule or buffer named 'conv1.weight'.
If I examine the state_dict from 'myModel' prior to load(), it contains entries like:
{[layers.conv2d-first.weight, {TorchSharp.Modules.Parameter}]}
{[layers.bnrm2d-first.weight, {TorchSharp.Modules.Parameter}]}
{[layers.bnrm2d-first.bias, {TorchSharp.Modules.Parameter}]}
{[layers.bnrm2d-first.running_mean, {TorchSharp.torch.Tensor}]}
{[layers.bnrm2d-first.running_var, {TorchSharp.torch.Tensor}]}
{[layers.bnrm2d-first.num_batches_tracked, {TorchSharp.torch.Tensor}]}
{[layers.blck-64-0.layers.blck-64-0-conv2d-1.weight, {TorchSharp.Modules.Parameter}]}
{[layers.blck-64-0.layers.blck-64-0-bnrm2d-1.weight, {TorchSharp.Modules.Parameter}]}
{[layers.blck-64-0.layers.blck-64-0-bnrm2d-1.bias, {TorchSharp.Modules.Parameter}]}
whereas the corresponding entries prior to saving from python are:
conv1.weight torch.Size([64, 3, 7, 7])
bn1.weight torch.Size([64])
bn1.bias torch.Size([64])
bn1.running_mean torch.Size([64])
bn1.running_var torch.Size([64])
bn1.num_batches_tracked torch.Size([])
layer1.0.conv1.weight torch.Size([64, 64, 3, 3])
layer1.0.bn1.weight torch.Size([64])
layer1.0.bn1.bias torch.Size([64])
I tried amending the ResNet.cs code to reflect the python names, but could not get them to exactly match.
I also tried calling load() with strict=false myModel.load(mPath, false);. This seemed to get past the Mismatched names exception, but throws another exception with message Too many bytes in what should have been a 7 bit encoded Int32.
I've been struggling with this for a couple of days now so would really appreciate any help you guys could offer.
Thanks
Jim
- 主要言語
- Jupyter Notebook
- スター
- 175
- フォーク
- 61
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/TorchSharpExamples のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 45/100
dotnet/TorchSharpExamples#56 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
dotnet/TorchSharpExamples#52 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 45/100
dotnet/TorchSharpExamples#50 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
dotnet/TorchSharpExamples#30 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
dotnet/TorchSharpExamples#29 ·
dotnet/TorchSharpExamples の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug module:classification
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
low AI-generated score register-submission
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
UKGovernmentBEIS/inspect_evals#2521 · コメント 2 件 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
stanfordnlp/stanza#1683 · コメント 2 件 ·
-
wer_score / mer_score / cer_score return 0 (a perfect lower-is-better score) for an empty prediction オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
stanford-crfm/helm#4359 ·