Models / resnet-18

ResNet-18

The 18-layer residual network for ImageNet-1k: a 7x7 stem, four stages of two residual blocks, and a linear classifier.

11.7M parametersresnetApache-2.0image-classificationvisionconvolutional

The forward entry with one level of blocks expanded. Every edge carries the tensor type the compiler inferred at that point, in the model's own generics.

ResNet-18: forwardResNet-18: forward

Entries ​

EntrySignature
forwardforward<B: Dim>(image: Tensor[B, 3, Height, Width; T]) -> Tensor[B, Classes; T]

Generics ​

The root block's generics as this checkpoint binds them.

Height224
Width224
Classes1000
Tf32

Blocks ​

Every block of the program with its members and functions, as linnet inspect prints them.

Block ​

text
resnet::Block<C: Dim, T: Float>
  sub first: ConvNorm<C, C, 3, 1, 1, T>
  sub second: ConvNorm<C, C, 3, 1, 1, T>
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, C, H, W; T]) -> Tensor[B, C, H, W; T]

Conv1d ​

text
std.nn.conv::Conv1d<Cin: Dim, Cout: Dim, K: Dim, Stride: Dim, Pad: Dim, T: Float = f32>
  param weight: Tensor[Cout, Cin, K; T]
  param bias: Tensor[Cout; T]?
  pub fn forward<B: Dim, L: Dim>(x: Tensor[B, Cin, L; T]) -> Tensor[B, Cout, 1 + (-1 * K + L + 2 * Pad) / Stride; T]

Conv2d ​

text
std.nn.conv::Conv2d<Cin: Dim, Cout: Dim, K: Dim, Stride: Dim, Pad: Dim, T: Float = f32>
  param weight: Tensor[Cout, Cin, K, K; T]
  param bias: Tensor[Cout; T]?
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, Cin, H, W; T]) -> Tensor[B, Cout, 1 + (-1 * K + H + 2 * Pad) / Stride, 1 + (-1 * K + W + 2 * Pad) / Stride; T]

Conv2dRect ​

text
std.nn.conv::Conv2dRect<Cin: Dim, Cout: Dim, KH: Dim, KW: Dim, StrideH: Dim, StrideW: Dim, PadH: Dim, PadW: Dim, T: Float = f32>
  param weight: Tensor[Cout, Cin, KH, KW; T]
  param bias: Tensor[Cout; T]?
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, Cin, H, W; T]) -> Tensor[B, Cout, 1 + (-1 * KH + H + 2 * PadH) / StrideH, 1 + (-1 * KW + W + 2 * PadW) / StrideW; T]

ConvNorm ​

text
resnet::ConvNorm<Cin: Dim, Cout: Dim, K: Dim, Stride: Dim, Pad: Dim, T: Float>
  sub convolution: Conv2d<Cin, Cout, K, Stride, Pad, T>
  param running_mean: Tensor[Cout; T]
  param running_var: Tensor[Cout; T]
  param weight: Tensor[Cout; T]
  param bias: Tensor[Cout; T]
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, Cin, H, W; T]) -> Tensor[B, Cout, 1 + (-1 * K + 2 * Pad + H) / Stride, 1 + (-1 * K + 2 * Pad + W) / Stride; T]

DownBlock ​

text
resnet::DownBlock<Cin: Dim, Cout: Dim, T: Float>
  sub first: ConvNorm<Cin, Cout, 3, 2, 1, T>
  sub second: ConvNorm<Cout, Cout, 3, 1, 1, T>
  sub shortcut: ConvNorm<Cin, Cout, 1, 2, 0, T>
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, Cin, H, W; T]) -> Tensor[B, Cout, 1 + (-1 + H) / 2, 1 + (-1 + W) / 2; T]

Linear ​

text
std.nn.linear::Linear<In: Dim, Out: Dim, T: Float = bf16>
  param weight: Tensor[Out, In; T]
  param bias: Tensor[Out; T]?
  pub fn forward<*S: Shape>(x: Tensor[*S, In; T]) -> Tensor[*S, Out; T]

Model ​

text
resnet::Model<Height: Dim, Width: Dim, Classes: Dim, T: Float = f32>
  sub stem: ConvNorm<3, 64, 7, 2, 3, T>
  sub stage_0_first: Block<64, T>
  sub stage_0_second: Block<64, T>
  sub stage_1: Stage<64, 128, T>
  sub stage_2: Stage<128, 256, T>
  sub stage_3: Stage<256, 512, T>
  sub classifier: Linear<512, Classes, T>
  pub entry forward<B: Dim>(image: Tensor[B, 3, Height, Width; T]) -> Tensor[B, Classes; T]

RmsNorm ​

text
std.nn.norm::RmsNorm<H: Dim, T: Float = bf16>
  param weight: Tensor[H; T]
  pub fn forward<*S: Shape>(x: Tensor[*S, H; T]) -> Tensor[*S, H; T]

Stage ​

text
resnet::Stage<Cin: Dim, Cout: Dim, T: Float>
  sub down: DownBlock<Cin, Cout, T>
  sub rest: Block<Cout, T>
  pub fn forward<B: Dim, H: Dim, W: Dim>(x: Tensor[B, Cin, H, W; T]) -> Tensor[B, Cout, 1 + (-1 + H) / 2, 1 + (-1 + W) / 2; T]