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: ResNetConfigImplementations§
Source§impl ResNet
impl ResNet
Sourcepub fn with_zero_weights(config: ResNetConfig) -> Self
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.
Sourcepub fn feature_channels(&self) -> usize
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.
Sourcepub fn from_hub(
model_id: &str,
depth: ResNetDepth,
output: OutputMode,
) -> Result<Self>
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.
pub fn from_hub_with_revision( model_id: &str, revision: &str, depth: ResNetDepth, output: OutputMode, ) -> Result<Self>
Sourcepub fn from_safetensors(
path: &Path,
depth: ResNetDepth,
output: OutputMode,
) -> Result<Self>
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).
Sourcepub fn from_state_dict(sd: &StateDict, config: ResNetConfig) -> Result<Self>
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.
Sourcepub fn forward(&self, images: &Tensor, batch: &BoundVariable) -> Result<Tensor>
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§
Auto Trait Implementations§
impl Freeze for ResNet
impl !RefUnwindSafe for ResNet
impl Send for ResNet
impl Sync for ResNet
impl Unpin for ResNet
impl UnsafeUnpin for ResNet
impl !UnwindSafe for ResNet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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