Struct burn_import::pytorch::LoadArgs
source · pub struct LoadArgs {
pub file: PathBuf,
pub key_remap: Vec<(Regex, String)>,
pub top_level_key: Option<String>,
pub debug: bool,
}
Expand description
Arguments for loading a PyTorch file.
§Fields
file
- The path to the file to load.key_remap
- A vector of tuples containing a regular expression and a replacement string. See regex::Regex::replace for more information.
§Notes
Use Netron to inspect the keys of the PyTorch file (.pt extension).
§Examples
use burn_import::pytorch::{LoadArgs, PyTorchFileRecorder};
use burn::record::FullPrecisionSettings;
use burn::record::Recorder;
let args = LoadArgs::new("tests/key_remap/key_remap.pt".into())
.with_key_remap("conv\\.(.*)", "$1"); // // Remove "conv" prefix, e.g. "conv.conv1" -> "conv1"
let record = PyTorchFileRecorder::<FullPrecisionSettings>::default()
.load(args)
.expect("Should decode state successfully");
Fields§
§file: PathBuf
The path to the file to load.
key_remap: Vec<(Regex, String)>
A list of key remappings.
top_level_key: Option<String>
Top-level key to load state_dict from the file. Sometimes the state_dict is nested under a top-level key in a dict.
debug: bool
Whether to print debug information.
Implementations§
source§impl LoadArgs
impl LoadArgs
sourcepub fn with_key_remap(self, pattern: &str, replacement: &str) -> Self
pub fn with_key_remap(self, pattern: &str, replacement: &str) -> Self
Sets key remapping.
§Arguments
pattern
- The Regex pattern to be replaced.replacement
- The pattern to replace with.
See Regex for the pattern syntax and Replacement for the replacement syntax.
sourcepub fn with_top_level_key(self, key: &str) -> Self
pub fn with_top_level_key(self, key: &str) -> Self
Sets the top-level key to load state_dict from the file. Sometimes the state_dict is nested under a top-level key in a dict.
§Arguments
key
- The top-level key to load state_dict from the file.
sourcepub fn with_debug_print(self) -> Self
pub fn with_debug_print(self) -> Self
Sets printing debug information on.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LoadArgs
impl RefUnwindSafe for LoadArgs
impl Send for LoadArgs
impl Sync for LoadArgs
impl Unpin for LoadArgs
impl UnwindSafe for LoadArgs
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more