notebook 3, max pooling testing

notebook 3, max pooling testing

by Oleksandr Tarasov -
Number of replies: 3

Hi guys,

I am referring to the cell with unit tests exactly after the MaxPooling implementation. First of all I have found no unittest import in the notebook before the cell is run, so the first run I got an import error. Second, the "setUp" method in the unittest tries to create and append an instance of the class Flatten:

class TestMaxPooling(unittest.TestCase):
def setUp(self):
...
self.layers = list()
self.layers.append(None)
self.layers.append(Flatten())
self.layers.append(None)
self.layers.append(SoftMax())
...

But there is no Flatten class in this notebook, did you mean our custom class "FlattenLayer" or any other class?

Could you please check and fix it?

In reply to Oleksandr Tarasov

Re: notebook 3, max pooling testing

by George Ciubotariu -

1. import unittest should solve your error.
2. You got it right, it's the FlattenLayer. You have to implement it first.

In reply to George Ciubotariu

Re: notebook 3, max pooling testing

by Oleksandr Tarasov -
Ok, I have added import and changed a class name, here we have one more lost classes. Same unit test class I reffered to:
 
def test_gradient_stride(self):
self.layers[0] = self.MaxPooling(neighborhood=(2, 2), stride=(2, 2))
self.layers[2] = self.FullyConnected(12, self.categories, 0.)

difference = gradient_check(self.layers, self.input_tensor, self.label_tensor)

self.assertLessEqual(np.sum(difference), 1e-6)

def test_gradient_overlapping_stride(self):
self.layers[0] = self.MaxPooling(neighborhood=(2, 2), stride=(2, 1))
self.layers[2] = self.FullyConnected(24, self.categories, 0.)

difference = gradient_check(self.layers, self.input_tensor, self.label_tensor)

self.assertLessEqual(np.sum(difference), 1e-6)

def test_gradient_subsampling_stride(self):

self.layers[0] = self.MaxPooling(neighborhood=(2, 2), stride=(3, 2))
self.layers[2] = self.FullyConnected(6, self.categories, 0.)
 
As you can see multiple functions try to create instances of MaxPooling class and FullyConnected layers. The MaxPooling class is defined in the next cell:

# TODO: run as homework!
test = TestMaxPooling()
test.MaxPooling = MaxPoolLayer
 
But at the same time, there is no FullyConnected layer in the notebook and no assignment of it to the test case class. So while running a test case we got an error:

Cell In[67], line 42
40 def test_gradient_stride(self):
41 self.layers[0] = self.MaxPooling(neighborhood=(2, 2), stride=(2, 2))
---> 42 self.layers[2] = self.FullyConnected(12, self.categories, 0.)
44 difference = gradient_check(self.layers, self.input_tensor, self.label_tensor)
46 self.assertLessEqual(np.sum(difference), 1e-6) AttributeError: 'TestMaxPooling' object has no attribute 'FullyConnected'
So, it looks like there should be a line like:
 
test.FullyConnected = FullyConnected
 
I can assume that it is just a normal dense layer which we also have done in the 1st notebook, but anyway could you please check it and fix it.
In reply to George Ciubotariu

Re: notebook 3, max pooling testing

by Oleksandr Tarasov -
Hi George,
could you please answer the question about the missed FullyConnected class at the unit test, right now broken test is a blocker for me.