CSC 4780/6780 Homework 11

$30.00 $24.00

Classifying Images with a Neural Net The rst place where deep neural nets excelled was image classi cation. One of the standard image classi cation tasks is Fashion-MNIST. The data set has small images ( 28 27) with 255 levels of gray scale: https://github.com/zalandoresearch/fashion-mnist The images are in 10 categories: 1.2 The Model Create a…

Rate this product

You’ll get a: zip file solution

 

Categorys:

Description

Rate this product
  • Classifying Images with a Neural Net

The rst place where deep neural nets excelled was image classi cation. One of the standard image classi cation tasks is Fashion-MNIST. The data set has small images ( 28 27) with 255 levels of gray scale:

https://github.com/zalandoresearch/fashion-mnist

The images are in 10 categories:

1.2 The Model

Create a le called FashNet.py that has the subclass of torch.nn.Module. Here is a diagram of the model you will create:

Your model will instantiate instances of the following classes in its init method

  • torch.nn.Linear

  • torch.nn.ReLU

  • torch.nn.Softmax

Then it will run the data through those layer in its forward method.

1.3 Training

You will write a program called fashion train.py that reads in the training data, instantiates an instance of FashNet, and trains it. It will print out the information about its layers. Every 50th iteration of training, it will print out its cross entropy loss and accuracy. You will train it for a total of 501 iterations. The output will look like this:

  • python3 fashion_train.py Input: (60000, 28, 28) Model parameters: fc1.weight:[256, 784] fc1.bias:[256] fc2.weight:[128, 256] fc2.bias:[128] fc3.weight:[64, 128] fc3.bias:[64] fc_last.weight:[10, 64] fc_last.bias:[10]

Total parameters: 242,762

Training:

  1. loss: 2.302428, accuracy: 15.13%

  1. loss: 1.696137, accuracy: 76.52%

  1. loss: 1.647088, accuracy: 81.50%

  1. loss: 1.637731, accuracy: 82.39%

  1. loss: 1.592654, accuracy: 86.85%

  1. loss: 1.554131, accuracy: 90.79%

  1. loss: 1.549938, accuracy: 91.18%

  1. loss: 1.536394, accuracy: 92.56%

  1. loss: 1.531210, accuracy: 93.09%

  1. loss: 1.524864, accuracy: 93.71%

  1. loss: 1.521189, accuracy: 94.06%

Training took 411.79 seconds

Wrote weights.pt

(Your output may not be exactly the same as mine. The weights are initialized randomly, and you can get di erent results based on that initialization.) Save this output to train out.txt

Use an ADAM optimizer. The learning rate of 0.01 worked well for me, but you should play with it.

fashion train.py will also plot its cross-entropy and accuracy on the training data as it is trained:

(This plot will be saved as learning.png.)

Finally, it will save the model’s state dictionary to a weights.pt using torch.save.

  • Testing

Create a program called fashion test.py that reads in the weights and the test data. It should compute the accuracy and create a confusion matrix in confusion.png.

It will look like this when it runs:

  • python3 fashion_test.py Input: (10000, 28, 28) Accuracy on test data: 88.24% Confusion:

[[855

3

10

32

2

0

87

0

11

0]

[

7

961

1

24

3

0

3

0

1

0]

[

19

2

811

12

86

1

68

0

1

0]

[

26

8

11

897

34

0

20

1

3

0]

[

3

2

104

34

811

0

43

0

3

0]

[

0

0

0

1

0

955

0

28

1

15]

[155

0

75

31

84

0

645

0

10

0]

[

0

0

0

0

0

16

0

964

0

20]

[

6

0

3

7

4

4

5

5

966

0]

[

0

0

0

0

0

6

1

34

0

959]]

Wrote

confusion.png

Save this output to test out.txt

The confusion matrix will look like this:

  • Batching

Sometimes the whole training data set is too big to work with e ciently. When this happens, we break the training data into “mini-batches”. You should break the 60,000 rows into 600 batches, each with 100 rows. The rows should be randomly selected. They should appear exactly once in the resulting batches.

Sometimes when you move to a batched training model you need to tweak your hyperparameters.

Copy fashion train.py to fashion train batches.py. Add batching to it.

In the original fashion train.py, you generated statistics using the whole training dataset. If the dataset is too big, you typically are content with using the stats from the last batch of the epoch. In this case, it means that the stats represent the loss and accuracy for 100 samples instead of the full 60,000.

You will probably need to adjust the learning rate of the optimizer.

The weighs generated by fashion train batches.py will work ne with fashion test.py

  • Criteria for success

If your name is Fred Jones, you will turn in a zip le called HW11 Jones Fred.zip of a directory called HW11 Jones Fred. It will contain:

  • fashion train.py

  • fashion train batches.py

  • fashion test.py

  • FashNet.py

  • weights.pt

  • confusion.png

  • learning.png

  • train out.txt

  • test out.txt

Be sure to format your python code with black before you submit it.

We would run your code like this:

cd HW11_Jones_Fred

python3 fashion_train.py

python3 fashion_test.py

python3 fashion_train_batches.py

python3 fashion_test.py

Do this work by yourself. Stackover ow is OK. A hint from another student is OK. Looking at another student’s code is not OK.

The template les for the python programs have import statements. Do not use any frameworks not in those import statements.

7

CSC 4780/6780 Homework 11
$30.00 $24.00