Comments (6)
怎么导入模型参数不参与训练 如:
model = models.vgg16(pretrained = True)
for param in model.parameters():
param.requires_grad = False
from torchsharp.
In TorchSharp it would look the same:
var model = ...;
foreach (var param in model.parameters())
param.requires_grad = False;
from torchsharp.
model = models.vgg16(pretrained = True) How to import the trained parameters of python tourch model
from torchsharp.
model = models.vgg16(pretrained = True) How to import the trained parameters of python tourch model
I suppose it could be another issue. I've tried that, but it seems that currently there are no beautiful solutions available.
If you don't mind, maybe you could download the pre-trained model with pytorch, and then try TorchSharp.PyBridge or exportsd.py to load it into csharp.
Actually torch.hub.download_url_to_file
could work in csharp. But I haven't found a simple enough way to resolve such a .pkl
file. Perhaps some more features should be added into TorchSharp.PyBridge
(to just load a dictionary of tensor, without a module or optimizer)?
from torchsharp.
from torchsharp.
I have uploaded the converted model to hugging face. Could the following code work for you?
using TorchSharp;
var huggingFace = "https://huggingface.co/";
// var huggingFace = "https://hf-mirror.com/";
var file = new FileInfo("./vgg16.dat");
if (!file.Exists)
torch.hub.download_url_to_file(
$"{huggingFace}yueyinqiu/vision-TorchSharp/resolve/main/VGG16_Weights.IMAGENET1K_V1",
file.FullName);
var model = torchvision.models.vgg16(weights_file: file.FullName);
from torchsharp.
Related Issues (20)
- Ranges implementation HOT 3
- Having trouble accessing training property of module HOT 1
- MoveToOuterDisposeScope that returns Parameter HOT 1
- Exception occurred when getting the state dictionary(state_dict). HOT 33
- To get the raw data array of a tensor, it takes some time. HOT 3
- ConvTranspose3d does not accept non-uniform kernelSize/stride values HOT 2
- TorchSharp memory issue HOT 19
- torch.finfo(dtype).min is 0 when dtype is torch.float16 while in pytorch the min value is -65504.0 HOT 3
- Will TorchSharp support exporting ONNX models in the future? HOT 8
- Why is the torch.unique function private? HOT 1
- "Console.WriteLine" in "Dotnet Interactive" after catching "Tensor invalid -- empty handle" exception HOT 1
- tensor to array with shape HOT 6
- should `Tensor.grad` be a property instead of a method? HOT 1
- System.AccessViolationException Error when using TorchSharp HOT 6
- Missing support for Quantized models HOT 3
- optimizers maximize HOT 2
- data loaders cannot work with some linq methods like `First` HOT 2
- in `RemoveDisposeScope`, we can't assume that `DisposeScopeStack.Peek() == disposeScope` HOT 4
- equivalent of PyTorch `data` HOT 1
- warnings cannot be accessed in notebooks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchsharp.