GithubHelp home page GithubHelp logo

Comments (4)

LaurentMazare avatar LaurentMazare commented on September 23, 2024 3

Actually I think this is the expected behavior (but the naming may be a bit confusing). vs.load(f) loads the weights for all the tensors currently in vs from file f. In your case vs is empty so nothing gets loaded and vs is still empty afterwards.
If you modify your code as follows to create the net (and so create the variables) before calling vs.load, their weights will actually be loaded from the file. Printing the var-store is not enough to confirm this as even without the vs.load call it would return the proper variable names and shapes hence I made italso print the weight values currently stored in one of the variables. You will notice that these values are identical between cargo run and the later call to cargo run weights.pt.
Let me know if this doesn't make sense, also maybe vs.load should be called vs.load_weight_values or something like that to be more explicit about what it does.

fn main() -> failure::Fallible<()> {
    let args: Vec<String> = std::env::args().collect();
    let mut vs = nn::VarStore::new(Device::Cpu);
    if args.len() < 2 {
      train(&mut vs)?;
      vs.save("weights.pt")?;
    } else {
      let _ = net(&vs.root());
      vs.load(args[1].as_str())?;
    }

    println!("{:#?}", vs.root());
    println!("{:#?}", Vec::<f64>::from(&vs.root().get("bias").unwrap()));
    Ok(())
}

from tch-rs.

LaurentMazare avatar LaurentMazare commented on September 23, 2024 1

Closing now, the doc has been updated to be clearer on this. Feel free to reopen if you encouter further issues.

from tch-rs.

grtlr avatar grtlr commented on September 23, 2024

Thanks for the quick response and the great clarification. Thinking about it now, it makes a lot of sense to do it that way. I think either vs.load or vs.load_weight_values is fine, maybe we could add a brief explanation in the documentation. With this in mind, vs.load_weight_values might encourage more users to actually read the documentation 😇.

from tch-rs.

kenkoooo avatar kenkoooo commented on September 23, 2024

I had the same problem and solved it by this thread! Thanks a lot!

from tch-rs.

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.