Struct EfficientNetConfig

Source
pub struct EfficientNetConfig {
    pub width_coefficient: f64,
    pub depth_coefficient: f64,
    pub resolution: usize,
    pub dropout_rate: f64,
    pub stages: Vec<EfficientNetStage>,
    pub input_channels: usize,
    pub num_classes: usize,
}
Expand description

Configuration for an EfficientNet model

Fields§

§width_coefficient: f64

Width multiplier

§depth_coefficient: f64

Depth multiplier

§resolution: usize

Resolution multiplier

§dropout_rate: f64

Dropout rate

§stages: Vec<EfficientNetStage>

Stage configurations

§input_channels: usize

Number of input channels (e.g., 3 for RGB)

§num_classes: usize

Number of output classes

Implementations§

Source§

impl EfficientNetConfig

Source

pub fn efficientnet_b0(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B0 configuration

Examples found in repository?
examples/efficientnet_example.rs (line 54)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    println!("EfficientNet Example");
7
8    // Create EfficientNet-B0 model for image classification
9    let input_channels = 3; // RGB images
10    let num_classes = 1000; // ImageNet classes
11
12    println!(
13        "Creating EfficientNet-B0 model with {} input channels and {} output classes",
14        input_channels, num_classes
15    );
16
17    // Create model
18    let model = EfficientNet::<f32>::efficientnet_b0(input_channels, num_classes)?;
19
20    // Create dummy input (batch_size=1, channels=3, height=224, width=224)
21    let input = Array::from_shape_fn(IxDyn(&[1, input_channels, 224, 224]), |_| {
22        rand::random::<f32>()
23    });
24
25    println!("Input shape: {:?}", input.shape());
26
27    // Forward pass
28    let output = model.forward(&input)?;
29
30    println!("Output shape: {:?}", output.shape());
31    println!("Output contains logits for {} classes", output.shape()[1]);
32
33    // Create EfficientNet-B3 model (larger model)
34    println!("\nCreating EfficientNet-B3 model...");
35
36    let model_b3 = EfficientNet::<f32>::efficientnet_b3(input_channels, num_classes)?;
37
38    // Create dummy input with higher resolution for B3 (300x300)
39    let input_b3 = Array::from_shape_fn(IxDyn(&[1, input_channels, 300, 300]), |_| {
40        rand::random::<f32>()
41    });
42
43    println!("Input shape for B3: {:?}", input_b3.shape());
44
45    // Forward pass
46    let output_b3 = model_b3.forward(&input_b3)?;
47
48    println!("Output shape for B3: {:?}", output_b3.shape());
49
50    // Create a custom EfficientNet model for smaller images
51    println!("\nCreating a custom EfficientNet model for smaller images...");
52
53    // Create simplified config with fewer stages
54    let mut custom_config = EfficientNetConfig::efficientnet_b0(input_channels, 10); // 10 classes
55
56    // Simplify by keeping only first 4 stages
57    custom_config.stages.truncate(4);
58
59    // Scale down the model
60    custom_config.width_coefficient = 0.5;
61    custom_config.depth_coefficient = 0.5;
62    custom_config.resolution = 32; // For CIFAR-10 size images
63
64    let custom_model = EfficientNet::<f32>::new(custom_config)?;
65
66    // Create dummy input for small images (32x32)
67    let small_input = Array::from_shape_fn(IxDyn(&[1, input_channels, 32, 32]), |_| {
68        rand::random::<f32>()
69    });
70
71    println!("Custom input shape: {:?}", small_input.shape());
72
73    // Forward pass
74    let custom_output = custom_model.forward(&small_input)?;
75
76    println!("Custom output shape: {:?}", custom_output.shape());
77    println!(
78        "Custom model produces logits for {} classes",
79        custom_output.shape()[1]
80    );
81
82    println!("\nEfficientNet example completed successfully!");
83
84    Ok(())
85}
Source

pub fn efficientnet_b1(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B1 configuration

Source

pub fn efficientnet_b2(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B2 configuration

Source

pub fn efficientnet_b3(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B3 configuration

Source

pub fn efficientnet_b4(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B4 configuration

Source

pub fn efficientnet_b5(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B5 configuration

Source

pub fn efficientnet_b6(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B6 configuration

Source

pub fn efficientnet_b7(input_channels: usize, num_classes: usize) -> Self

Create EfficientNet-B7 configuration

Source

pub fn scale_channels(&self, channels: usize) -> usize

Scale channels based on width coefficient

Source

pub fn scale_depth(&self, depth: usize) -> usize

Scale depth based on depth coefficient

Trait Implementations§

Source§

impl Clone for EfficientNetConfig

Source§

fn clone(&self) -> EfficientNetConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EfficientNetConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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> 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