simet.models.sample_simple_cnn¶
simet.models.sample_simple_cnn ¶
SimpleCNN ¶
SimpleCNN(num_classes=10)
Bases: Module
A small convolutional classifier (C64 head with global average pooling).
Architecture
features: Conv2d(3→32, k=3, p=1) → ReLU → MaxPool2d(2) Conv2d(32→64, k=3, p=1) → ReLU → MaxPool2d(2) global_pool: AdaptiveAvgPool2d(output_size=1) classifier: Flatten → Linear(64→128) → ReLU → Dropout(p=0.5) → Linear(128→num_classes)
Input/Output:
- Input tensor shape: (N, 3, H, W) with H and W ≥ 4 (multiples of 4 recommended
due to two 2×2 pools). Typical usage is 64×64 images normalized to a reasonable range.
- Output tensor shape: (N, num_classes) (unnormalized logits).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_classes
|
int
|
Number of output classes (size of the final logits vector). Defaults to 10. |
10
|
Attributes:
| Name | Type | Description |
|---|---|---|
features |
Sequential
|
Two conv blocks with ReLU and 2×2 max pooling. |
global_pool |
AdaptiveAvgPool2d
|
Global average pooling to 1×1 per channel. |
classifier |
Sequential
|
MLP head producing class logits. |
Example
model = SimpleCNN(num_classes=2).eval() x = torch.randn(8, 3, 64, 64) logits = model(x) logits.shape torch.Size([8, 2])
Source code in simet/models/sample_simple_cnn.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
forward ¶
forward(x)
Compute class logits for a batch of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Logits of shape |
Tensor
|
|
Source code in simet/models/sample_simple_cnn.py
62 63 64 65 66 67 68 69 70 71 72 73 74 | |