1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::internal::*;
use std::fmt::Debug;
use std::io::Read;
use std::path::Path;
pub trait Framework<ProtoModel, Model>
where
ProtoModel: Debug,
{
fn proto_model_for_read(&self, reader: &mut dyn Read) -> TractResult<ProtoModel>;
fn model_for_proto_model(&self, proto: &ProtoModel) -> TractResult<Model>;
fn proto_model_for_path(&self, p: impl AsRef<Path>) -> TractResult<ProtoModel> {
let mut r = std::fs::File::open(p.as_ref())
.with_context(|| format!("Could not open {:?}", p.as_ref()))?;
self.proto_model_for_read(&mut r)
}
fn model_for_read(&self, r: &mut dyn Read) -> TractResult<Model> {
let proto_model = self.proto_model_for_read(r)?;
self.model_for_proto_model(&proto_model)
}
fn model_for_path(&self, p: impl AsRef<Path>) -> TractResult<Model> {
let mut r = std::fs::File::open(p.as_ref())
.with_context(|| format!("Could not open {:?}", p.as_ref()))?;
self.model_for_read(&mut r)
}
}