Skip to content

Commit b40a0a6

Browse files
committed
Merge branch 'main' of github.com:SFI-Visual-Intelligence/Collaborative-Coding-Exam into johan/devbranch
2 parents 7551c14 + dff0f45 commit b40a0a6

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

doc/Magnus_page.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ Magnus Individual Task
22
======================
33

44
## Task overview
5-
In addition to the overall task, I was tasked to implement a three layer linear network, a dataset loader for the SVHN dataset, and a entropy metric.
5+
In addition to the overall task, I was tasked to implement a three layer linear network, a dataset loader for the SVHN dataset, and a entropy metric. This document details that work.
66

77
## Network Implementation In-Depth
8-
For the network part I was tasked with making a three-layer linear network where each layer conists of 133 neurons. This is a fairly straightforward implementation where we make a custom class which inherits from the PyTorch Module class. This allows for our class to have two methods. The __init__ method and a forward method. When we make an instance of the class we'll be able to call the instance like we would call a function, and have it run the forward method.
8+
For the network part I was tasked with making a three-layer linear network where each layer conists of 133 neurons. This is a fairly straightforward implementation where we make a custom class which inherits from the PyTorch Module class. This allows the class to be as simple as two methods; The __init__ method and a __forward__ method. Inheriting from the module class allows us to call an instance of the class like a function, and the __forward__ method will be called.
99

1010
The network is initialized with the following metrics:
1111
* image_shape
@@ -21,9 +21,9 @@ Each input is flattened over the channel, height and width channels. Then they a
2121

2222

2323
## SVHN Dataset In-Depth
24-
The dataloader I was tasked with making is to load the well-known SVHN dataset. This is a RGB dataset with real-life digits taken from house numbers. The class inherits from the torch Dataset class, and has four methods:
24+
The dataloader I was tasked with making is to load the well-known SVHN dataset. This is a RGB dataset with real-life digits taken from house numbers. The class tasked with loading the data inherits from the torch Dataset class, and has four methods:
2525
* __init__ : initialized the instance of the class
26-
* _create_h5py: Creates the h5 object containing data from the downloaded .mat files for ease of use
26+
* __create_h5py__: Creates the h5 object containing data from the downloaded .mat files for ease of use
2727
* __len__ : Method needed in use of the DataLoader class. Returns length of the dataset
2828
* __getitem__ : Method needed in use of the DataLoader class. Loads a image - label pair, applies any defined image transformations, and returns both image and label.
2929

@@ -37,7 +37,7 @@ The __init__ method takes in a few arguments.
3737

3838
In the init we check for the existence of the SVHN dataset. If it does not exist, then we run the _create_h5py method which will be explained later. Then the labels are loaded into memory as they are needed for the __len__ method among other things.
3939

40-
The _create_h5py method downloads a given SVHN set (train or test). We also change the label 10 to 0, as the SVHN dataset starts at index 1, with 10 representing images with the digit zero. After the download, we create two .h5 files. One with the labels and one with the images.
40+
The __create_h5py__ method downloads a given SVHN set (train or test). We also change the label 10 to 0, as the SVHN dataset starts at index 1, with 10 representing images with the digit zero. After the download, we create two .h5 files. One with the labels and one with the images.
4141

4242
Lastly, in __getitem__ we take index (number between 0 and length of label array). We retrive load the image h5 file, and retrive the row corresponding to the index.
4343
We then convert the image to an Pillow Image object, then apply the defined transforms before returning the image and label.
@@ -46,6 +46,7 @@ We then convert the image to an Pillow Image object, then apply the defined tran
4646

4747
## Entropy Metric In-Depth
4848
The EntropyPrediction class' main job is to take some inputs from the MetricWrapper class and store the batchwise Shannon Entropy metric of those inputs. The class has four methods with the following jobs:
49+
4950
* __init__ : Initialize the class.
5051
* __call__ : Main method which is used to calculate and store the batchwise shannon entropy.
5152
* __returnmetric__ : Returns the collected metric.
@@ -54,7 +55,7 @@ The EntropyPrediction class' main job is to take some inputs from the MetricWrap
5455
The __init__ method has two arguments, both present for compatability issues. However, the num_classes argument is used as a check in the __call__ method to assert the input is of correctly assumed size.
5556

5657
In __call__ we get both true labels and model logit scores for each sample in the batch as input. We're calculating Shannon Entropy, not KL-divergence, so the true labels aren't actually needed.
57-
With permission I've used the scipy implementation to calculate entropy here. We apply a softmax over the logit values, then calculate the Shannon Entropy, and make sure to remove any Inf values which might arise from a perfect guess/distribution.
58+
With permission from Kristoffer I've used the scipy implementation to calculate entropy here. We apply a softmax over the logit values, then calculate the Shannon Entropy, and make sure to remove any Inf values which might arise from a perfect guess/distribution.
5859

5960

6061

doc/index.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Our code documentation
22

3-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
4-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
5-
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
6-
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
7-
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
8-
culpa qui officia deserunt mollit anim id est laborum.
3+
This documentation lays out the code documentation of use for the FYS-8805 Collaborative Coding and Reproducible Research code as well as the participants individual documentation for the final evaluation.
94

105
:::{toctree}
116
:maxdepth: 1

0 commit comments

Comments
 (0)