CollaborativeCoding.models.christian_model

Attributes

x

Classes

CNNBlock

CNN block with Conv2d, MaxPool2d, and ReLU.

ChristianModel

Simple CNN model for image classification.

Functions

find_fc_input_shape(image_shape, *cnn_layers)

Find the shape of the input to the fully connected layer.

Module Contents

class CollaborativeCoding.models.christian_model.CNNBlock(in_channels, out_channels)

Bases: torch.nn.Module

CNN block with Conv2d, MaxPool2d, and ReLU.

Args

in_channelsint

Number of input channels.

out_channelsint

Number of output channels.

conv
maxpool
relu
forward(x)
CollaborativeCoding.models.christian_model.find_fc_input_shape(image_shape, *cnn_layers)

Find the shape of the input to the fully connected layer.

Code inspired by @Seilmast (https://github.com/SFI-Visual-Intelligence/Collaborative-Coding-Exam/issues/67#issuecomment-2651212254)

Args

image_shapetuple(int, int, int)

Shape of the input image (C, H, W).

cnn_layersnn.Module

List of CNN layers.

Returns

int

Number of elements in the input to the fully connected layer.

class CollaborativeCoding.models.christian_model.ChristianModel(image_shape, num_classes)

Bases: torch.nn.Module

Simple CNN model for image classification.

Args

image_shapetuple(int, int, int)

Shape of the input image (C, H, W).

num_classesint

Number of classes in the dataset.

Processing Images

Input: (N, C, H, W)

N: Batch size C: Number of input channels H: Height of the input image W: Width of the input image

Example: For grayscale images, C = 1.

Input Image Shape: (5, 1, 16, 16) CNN1 Output Shape: (5, 50, 8, 8) CNN2 Output Shape: (5, 100, 4, 4) FC Output Shape: (5, num_classes)

cnn1
cnn2
fc1
forward(x)
CollaborativeCoding.models.christian_model.x