You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for bringing this rust wrapper! I would like to expose a model object that is built from a helper. Up to now, I did not manage to implement such a simple code. I am almost sure that this is due to a lack of rust knowledge, and especially lifetimes. Here is my code:
use onnxruntime::{LoggingLevel, GraphOptimizationLevel};
use onnxruntime::environment::Environment;
use onnxruntime::session::Session;
pub struct Model<'a> {
environment: Environment,
session: Session<'a>,
}
impl<'a> Model<'a> {
pub fn new() -> Model<'a> {
let environment = Environment::builder()
.with_name("foo")
.with_log_level(LoggingLevel::Verbose)
.build().expect("building environment");
let session = environment.new_session_builder().unwrap()
.with_optimization_level(GraphOptimizationLevel::Basic).unwrap()
.with_number_threads(1).unwrap()
.with_model_from_file("foo.onnx").unwrap();
Model {
environment: environment,
session: session,
}
}
//pub fn set_model(self, model_path: &String)
//pub fn run(self, tensors)
}
This is in a dedicated module. When I try to use it from another function, I have this compilation error:
error[E0515]: cannot return value referencing local variable `environment`
--> src/model.rs:23:9
|
18 | let session = environment.new_session_builder().unwrap()
| ----------- `environment` is borrowed here
...
23 | / Model {
24 | | environment: environment,
25 | | session: session,
26 | | }
| |_________^ returns a value referencing data owned by the current function
All the examples I found allocate the environment and the session objects as local variables in main. Moreover, the environment is used only once. I would like to build them indirectly and update the session (So I need to re-use the environment).
Can anybody give me some hints on how I can allocate a Model object that contains the environment and session objects in it? I tried to Box the environment object, and to put the session in an Option to defer its creation without success.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello there,
Thanks for bringing this rust wrapper! I would like to expose a model object that is built from a helper. Up to now, I did not manage to implement such a simple code. I am almost sure that this is due to a lack of rust knowledge, and especially lifetimes. Here is my code:
This is in a dedicated module. When I try to use it from another function, I have this compilation error:
All the examples I found allocate the environment and the session objects as local variables in main. Moreover, the environment is used only once. I would like to build them indirectly and update the session (So I need to re-use the environment).
Can anybody give me some hints on how I can allocate a Model object that contains the environment and session objects in it? I tried to Box the environment object, and to put the session in an Option to defer its creation without success.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions