Revision 834dd58df38a61e90159678d07f552bb14503ff0 (click the page title to view the current version)

Regression

Changes from 834dd58df38a61e90159678d07f552bb14503ff0 to current

---
title: Neural Networks for Regression
categories: session
---

# Reading
Reading
: Szeliski 2022 Chapter 5 (again)

+ Szeliski 2022 Chapter 5
Briefing
: quick status 

# Exercise 3. Regression.
Evaluation
: Reference group at 1.30pm ([mal](Referansegruppe_mal_engelsk_revidert 2016.odt))

Debrief
: 3.15pm

# Exercise 1. Regression.

This exercises is included to illustrate breadth.  Regression is
different from the other problems we have seen in classification,
object detection, and segmentation, in that we try to estimate
one or more continuous parameters.

One in-house project is to classify images of remote galaxies,
which are often distorted due to the gravity of dark matter.
This effect is known as gravitational lensing.

A sample dataset can be found at
[github](https://github.com/CosmoAI-AES/datasets2022/tree/main/Exercise2022).
This directory contains
Here, the input is images, as we are used to.
We want to predict physical quantities such as the true position of the
source, and the mass (Einstein radius) of the lens.

The  directory contains

+ A data file, `sphere-pm.csv` 
+ 10000 images of distorted galaxies
+ A python file `Dataset.py` defining a subclass of `Dataset`
  to manage these data

The CSV file has the form
```
index,filename,source,lens,chi,x,y,einsteinR,sigma,sigma2,theta,nterms
"00001",image-00001.png,s,p,50,30,40,19,31,0,0,16
```
The interesting columns are the filename which points to the
input image,  and
the four output variables $x$, $y$, `einsteinR`, and $\sigma$.
These variables are integers or floating point values, and make
a case for regression
The other columns are associated with more advanced problem instances
and should be ignored.

1.  Study the Dataset class `Dataset.py`.
    How does it compare to how you have managed datasets in
    PyTorch so far?
    How is the dataset managed?
2.  Use this class to test if you can train a network to determine the
    four outputs for an image.

# Exercise 4.  Own Data (Optional)
# Exercise 2.  Own Data (classification)

Making your own training data may be difficult, because of the
large quantity of data that you need, but if you want to give it
a try, I would recommend this. 
a try, I would recommend the following.
You can use any of the APIs and models we have seen.

1.  Team up with everybody else who wants to do this problem.
2.  Each team member makes a set of hand-drawn digits or letters,
    at least ten versions of each digit each.
3.  Digitise the digits into image files.  Make sure that everybody
    uses the same resolution (image size in pixels).  
    + The resolution must be large enough to make digits recognisable,
      but small enough to save computational power.
    + Somewhere between $28\times28$ (same as the MIST dataset)
      and $64\times64$ sounds reasonable.
4.  Gather the images into a dataset with their labels (digit value).
    You may use Exercise 3 as an example.
5.  Merge and share the dataset.
6.  Train and test a neural network to read the digits.
7.  Try different networks, at least the ones you have used in previous
    exercises.