Struct Interpolate2d
pub struct Interpolate2d {
pub output_size: Option<[usize; 2]>,
pub scale_factor: Option<[f32; 2]>,
pub mode: InterpolateMode,
pub align_corners: bool,
}Expand description
Interpolate module for resizing tensors with shape [N, C, H, W].
This struct represents an interpolation module that can resize tensors using various interpolation methods. It provides flexibility in specifying either an output size or a scale factor for resizing, along with options for the interpolation mode.
The module can be used to upsample or downsample tensors, preserving the number of channels and batch size while adjusting the height and width dimensions.
The module can be created using the Interpolate2dConfig struct and the
init method, which returns an instance of the Interpolate2d struct.
Fields§
§output_size: Option<[usize; 2]>Output size of the interpolated tensor
scale_factor: Option<[f32; 2]>Scale factor for resizing the input tensor
mode: InterpolateModeInterpolation mode used for resizing
align_corners: boolWhether to align corner pixels
Implementations§
§impl Interpolate2d
impl Interpolate2d
pub fn forward(&self, input: Tensor<4>) -> Tensor<4>
pub fn forward(&self, input: Tensor<4>) -> Tensor<4>
Performs the forward pass of the interpolation module
§Arguments
input- Input tensor with shape [N, C, H, W]
§Returns
Resized tensor with shape [N, C, H’, W’], where H’ and W’ are determined by the output_size or scale_factor specified in the module configuration
§Panics
Panics unless exactly one of output_size or scale_factor is set.
§Example
let input = Tensor::<4>::random([1, 3, 64, 64], Distribution::Uniform(0.0, 1.0), &device);
let interpolate = Interpolate2dConfig::new()
.with_output_size(Some([128, 128]))
.init();
let output = interpolate.forward(input);
assert_eq!(output.dims(), [1, 3, 128, 128]);Trait Implementations§
§impl Clone for Interpolate2d
impl Clone for Interpolate2d
§fn clone(&self) -> Interpolate2d
fn clone(&self) -> Interpolate2d
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Interpolate2d
impl Debug for Interpolate2d
§impl Display for Interpolate2d
impl Display for Interpolate2d
§impl Module for Interpolate2d
impl Module for Interpolate2d
§fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor,
fn visit<V>(&self, _visitor: &mut V)where
V: ModuleVisitor,
§fn map<M>(self, _mapper: &mut M) -> Interpolate2dwhere
M: ModuleMapper,
fn map<M>(self, _mapper: &mut M) -> Interpolate2dwhere
M: ModuleMapper,
§fn to_device(self, _: &Device) -> Interpolate2d
fn to_device(self, _: &Device) -> Interpolate2d
§fn fork(self, _: &Device) -> Interpolate2d
fn fork(self, _: &Device) -> Interpolate2d
§fn collect_devices(&self, devices: Vec<Device>) -> Vec<Device>
fn collect_devices(&self, devices: Vec<Device>) -> Vec<Device>
§fn materialize(self) -> Interpolate2d
fn materialize(self) -> Interpolate2d
§fn valid(&self) -> Interpolate2d
fn valid(&self) -> Interpolate2d
§fn train(self) -> Interpolate2d
fn train(self) -> Interpolate2d
§fn devices(&self) -> Vec<Device>
fn devices(&self) -> Vec<Device>
§fn set_require_grad(self, require_grad: bool) -> Self
fn set_require_grad(self, require_grad: bool) -> Self
§fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
fn set_require_grad_group(self, group: ParamGroup, require_grad: bool) -> Self
§fn no_grad(self) -> Self
fn no_grad(self) -> Self
§fn freeze_group(self, group: ParamGroup) -> Self
fn freeze_group(self, group: ParamGroup) -> Self
§fn unfreeze_group(self, group: ParamGroup) -> Self
fn unfreeze_group(self, group: ParamGroup) -> Self
§fn num_params(&self) -> usize
fn num_params(&self) -> usize
§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§fn quantize_weights_group(
self,
quantizer: &mut Quantizer,
group: ParamGroup,
) -> Self
fn quantize_weights_group( self, quantizer: &mut Quantizer, group: ParamGroup, ) -> Self
§fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
Reparameterizer. Read more§fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
§fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read more§fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read more§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read more§fn save_file<P>(self, path: P) -> Result<(), RecordError>
fn save_file<P>(self, path: P) -> Result<(), RecordError>
§fn load_file<P>(self, path: P) -> Self
fn load_file<P>(self, path: P) -> Self
§fn try_load_file<P>(self, path: P) -> Result<Self, RecordError>
fn try_load_file<P>(self, path: P) -> Result<Self, RecordError>
§impl ModuleDisplay for Interpolate2d
impl ModuleDisplay for Interpolate2d
§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
§fn custom_content(&self, content: Content) -> Option<Content>
fn custom_content(&self, content: Content) -> Option<Content>
§fn format(&self, passed_settings: DisplaySettings) -> String
fn format(&self, passed_settings: DisplaySettings) -> String
§impl ModuleDisplayDefault for Interpolate2d
impl ModuleDisplayDefault for Interpolate2d
Auto Trait Implementations§
impl Freeze for Interpolate2d
impl RefUnwindSafe for Interpolate2d
impl Send for Interpolate2d
impl Sync for Interpolate2d
impl Unpin for Interpolate2d
impl UnsafeUnpin for Interpolate2d
impl UnwindSafe for Interpolate2d
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more