Skip to main content

ResNet

Struct ResNet 

Source
pub struct ResNet {
    pub config: ResNetConfig,
    /* private fields */
}
Expand description

Image classification / feature backbone. Construct via one of the loaders (ResNet::from_hub, ResNet::from_safetensors, or ResNet::from_state_dict) — the empty-tensor placeholders in the layer structs are not usable until weights are loaded.

Fields§

§config: ResNetConfig

Implementations§

Source§

impl ResNet

Source

pub fn with_zero_weights(config: ResNetConfig) -> Self

Build with all-zero weight placeholders. Used by every loader before a load_state_dict call, and exposed publicly for round-trip tests.

Source

pub fn feature_channels(&self) -> usize

Number of output channels after stage 4 (before any FC head). Useful when consumers want to pre-allocate downstream buffers.

Source

pub fn from_hub( model_id: &str, depth: ResNetDepth, output: OutputMode, ) -> Result<Self>

Download model.safetensors from a HuggingFace Hub repository at the main revision and load it. The repo must publish a flat timm / torchvision-style state dict.

Source

pub fn from_hub_with_revision( model_id: &str, revision: &str, depth: ResNetDepth, output: OutputMode, ) -> Result<Self>

Source

pub fn from_safetensors( path: &Path, depth: ResNetDepth, output: OutputMode, ) -> Result<Self>

Load from a local model.safetensors. The file must use the timm / torchvision key layout (see the module-level docs for the keys).

Source

pub fn from_state_dict(sd: &StateDict, config: ResNetConfig) -> Result<Self>

Build from a preloaded state dict. Runs remap::fold_batchnorm first to translate running_var into invstd and drop num_batches_tracked — the loaded layer structs read directly from the post-fold layout.

Source

pub fn forward(&self, images: &Tensor, batch: &BoundVariable) -> Result<Tensor>

Run the full network on images [max_b, 3, H, W], shrunk to the batch variable’s bound value before the stem. Returns either classification logits [B, num_classes] or the final feature map [B, 512*exp, H/32, W/32], depending on ResNetConfig::output.

Trait Implementations§

Source§

impl Clone for ResNet

Source§

fn clone(&self) -> ResNet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl HasStateDict for ResNet

Source§

fn state_dict(&self, prefix: &str) -> StateDict

Source§

fn load_state_dict(&mut self, sd: &StateDict, prefix: &str) -> Result<(), Error>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more