Struct tch::nn::VarStore [−][src]
A VarStore is used to store variables used by one or multiple layers. It specifies a single device where all variables are stored.
Fields
variables_: Arc<Mutex<Variables>>
Implementations
impl VarStore
[src]
pub fn new(device: Device) -> VarStore
[src]
Creates a new var-store located on the specified device.
pub fn device(&self) -> Device
[src]
Gets the device for this var-store.
pub fn len(&self) -> usize
[src]
Returns the number of tensors currently stored on this var-store.
pub fn is_empty(&self) -> bool
[src]
Returns true if no tensors are currently stored on this var-store.
pub fn trainable_variables(&self) -> Vec<Tensor>
[src]
Returns all the trainable variables for this var-store.
pub fn variables(&self) -> HashMap<String, Tensor>
[src]
Returns all variables along with their names.
pub fn root(&self) -> Path<'_>
[src]
Gets the root path for this variable store.
Variables are named and organized using paths. This function returns the top level path for the var store and can be combined with ‘/’ to create sub-paths.
pub fn save<T: AsRef<Path>>(&self, path: T) -> Result<(), TchError>
[src]
Saves the var-store variable values to a file.
Weight values for all the tensors currently stored in the var-store gets saved in the given file.
pub fn load<T: AsRef<Path>>(&mut self, path: T) -> Result<(), TchError>
[src]
Loads the var-store variable values from a file.
Weight values for all the tensors currently stored in the var-store gets loaded from the given file. Note that the set of variables stored in the var-store is not changed, only the values for these tensors are modified.
pub fn load_partial<T: AsRef<Path>>(
&mut self,
path: T
) -> Result<Vec<String>, TchError>
[src]
&mut self,
path: T
) -> Result<Vec<String>, TchError>
Loads the var-store variable values from a file if it exists.
Weight values for the tensors currently stored in the var-store and the given file get loaded from the given file. If a variable in the var store is not present in the given file, it is skipped and its values are not updated. This method should be used if pre-trained weight for only parts of the model are available. Note that the set of variables stored in the var-store is not changed, only the values for these tensors are modified.
Returns a String Vector containing the names of missing variables.
pub fn freeze(&mut self)
[src]
Freezes a var store.
Gradients for the variables in this store are not tracked anymore.
pub fn unfreeze(&mut self)
[src]
Unfreezes a var store.
Gradients for the variables in this store are tracked again.
pub fn copy(&mut self, src: &VarStore) -> Result<(), TchError>
[src]
Copies variable values from a source var store to this var store.
All the variables in this var store have to exist with the same name in the source var store, otherwise an error is returned.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for VarStore
impl Send for VarStore
impl Sync for VarStore
impl Unpin for VarStore
impl UnwindSafe for VarStore
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,