Skip to content

Commit 6ace13a

Browse files
committed
added Jan doc
1 parent 7568140 commit 6ace13a

File tree

5 files changed

+97
-11
lines changed

5 files changed

+97
-11
lines changed

doc/Jan_page.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Jan Individual Task
2+
======================
3+
4+
## Task Overview
5+
In addition to the overall task, I was assigned the implementation of a multi-layer perceptron model, a dataset loader for a subset of the MNIST dataset, and an accuracy metric.
6+
7+
## Network Implementation In-Depth
8+
For the network part, I was tasked with making a simple MLP network model for image classification tasks. The model consists of two hidden layers with 100 neurons each followed by a leaky-relu activation. This implementation involves creating a custom class that inherits from the PyTorch `nn.Module` class. This allows our class to have two methods: the `__init__` method and a `forward` method. When we create an instance of the class, we can call the instance like a function, which will run the `forward` method.
9+
10+
The network is initialized with the following parameters:
11+
* `image_shape`
12+
* `num_classes`
13+
14+
The `image_shape` argument provides the shape of the input image (channels, height, width) which is used to correctly initialize the input size of the first layer. The `num_classes` argument defines the number of output neurons, corresponding to the number of classes in the dataset.
15+
16+
The forward method in this class processes the input as follows:
17+
1. Flattens the input image.
18+
2. Passes the flattened input through the first fully connected layer (`fc1`).
19+
3. Applies a LeakyReLU activation function.
20+
4. Passes the result through the second fully connected layer (`fc2`).
21+
5. Applies another LeakyReLU activation function.
22+
6. Passes the result through the output layer (`out`).
23+
24+
## MNIST Dataset In-Depth
25+
For the dataset part, I was tasked with creating a custom dataset class for loading a subset of the MNIST dataset containing digits 0 to 3. This involved creating a class that inherits from the PyTorch `Dataset` class.
26+
27+
The class is initialized with the following parameters:
28+
* `data_path`
29+
* `sample_ids`
30+
* `train` (optional, default is False)
31+
* `transform` (optional, default is None)
32+
* `nr_channels` (optional, default is 1)
33+
34+
The `data_path` argument stores the path to the four binary files containing MNIST dataset. The verification of presence of these files and their download, if necessary, is facilitated by the `Downloader`class. The `sample_ids` parameter contains the indices of images and their respective labels that are to be loaded from MNIST dataset. Filtering and random splitting of these indices is performed within the `load_data`function. `train`is a boolean flag indicating whether to load data from training (for training and validation splits) or from testing (test split) part of the MNIST dataset. `transform` is a callable created with `torch.compose()` to be applied on the images. `nr_channels` is not used in this dataset, only included for compatibility with other functions.
35+
36+
The class has two main methods:
37+
* `__len__`: Returns the number of samples in the dataset.
38+
* `__getitem__`: Retrieves the image and label at the specified index.
39+
40+
## Accuracy Metric In-Depth
41+
For the metric part, I was tasked with creating an accuracy metric class. The `Accuracy` class computes the accuracy of a model's predictions. The class is initialized with the following parameters:
42+
* `num_classes`
43+
* `macro_averaging` (optional, default is False)
44+
45+
The `num_classes` argument specifies the number of classes in the classification task. The `macro_averaging`argument is a boolean flag specifying whether to compute the accuracy using micro or macro averaging.
46+
47+
The class has the following methods:
48+
* `forward`: Stores the true and predicted labels computed on a batch level.
49+
* `_macro_acc`: Computes the macro-averaged accuracy on stored values.
50+
* `_micro_acc`: Computes the micro-averaged accuracy on stored values.
51+
* `__returnmetric__`: Returns the computed accuracy based on the averaging method for all stored predictions.
52+
* `__reset__`: Resets the stored true and predicted labels.
53+
54+
The `forward` method takes the true labels and predicted labels as input and stores them. The `_macro_acc` method computes the macro-average accuracy by averaging the accuracy for each class. The `_micro_acc` method computes the micro-average accuracy by calculating the overall accuracy. The `__returnmetric__` method returns the computed accuracy based on the averaging method. The `__reset__` method resets the stored true and predicted labels to prepare for the next epoch.

doc/about.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# About this code
22

3-
Work is still in progress ...
3+
This project was created as part of a Collaboratice Coding and Reproducible Research special curriculum, held at UiT in february 2025.

doc/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
88
culpa qui officia deserunt mollit anim id est laborum.
99

1010
:::{toctree}
11-
:maxdepth: 2
12-
:caption: Some caption
11+
:maxdepth: 1
12+
:caption: Table of contents
1313

1414
about.md
1515
Magnus_page.md
16+
Jan_page.md
1617
:::
1718

18-
Individual Sections
19-
===================
19+

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies = [
99
"h5py>=3.12.1",
1010
"isort>=6.0.0",
1111
"jupyterlab>=4.3.5",
12+
"myst-parser>=4.0.1",
1213
"numpy>=2.2.2",
1314
"pandas>=2.2.3",
1415
"pip>=25.0",

uv.lock

Lines changed: 37 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)