Coder Social home page Coder Social logo

Comments (6)

zengnanhua avatar zengnanhua commented on August 21, 2024

怎么导入模型参数不参与训练 如:
model = models.vgg16(pretrained = True)
for param in model.parameters():
param.requires_grad = False

from torchsharp.

shaltielshmid avatar shaltielshmid commented on August 21, 2024

In TorchSharp it would look the same:

var model = ...;
foreach (var param in model.parameters())
    param.requires_grad = False;

from torchsharp.

zengnanhua avatar zengnanhua commented on August 21, 2024

model = models.vgg16(pretrained = True) How to import the trained parameters of python tourch model

from torchsharp.

yueyinqiu avatar yueyinqiu commented on August 21, 2024

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.

yueyinqiu avatar yueyinqiu commented on August 21, 2024

#713

from torchsharp.

yueyinqiu avatar yueyinqiu commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.