Comments (4)
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.
Closing now, the doc has been updated to be clearer on this. Feel free to reopen if you encouter further issues.
from tch-rs.
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.
I had the same problem and solved it by this thread! Thanks a lot!
from tch-rs.
Related Issues (20)
- Double free or corruption (fasttop) HOT 1
- grads become zeros after a short period of training on metal backend
- Can we `.set_retains_grad(true)` ?
- model in rust, optimizer.step in python
- Preserving gradients with copy()? HOT 2
- Can't compile or test tch-rs HOT 3
- What if I am not using `pyo3==0.18.3`? HOT 4
- Error when building burn on Windows when upgrading to tch 0.16 HOT 4
- Can you help me setting environment variables? HOT 2
- la HOT 1
- Publish pyo3-tch 0.16 HOT 3
- getting gradient for intermediate tensors
- Unable to compile on arch-linux HOT 2
- torch download and build location
- Can't compile static HOT 3
- Rust-bert does not work with Debian 12 errors HOT 1
- Any ideas? HOT 4
- M2 mac os throw error: "found architecture 'x86_64', required architecture 'arm64'" HOT 2
- error adding symbols: DSO missing from command line HOT 2
- Support of X86 quantization engine as in pytorch?
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 tch-rs.