Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does nn.conv2D implement the feature map table of LeNet-5? #16

Open
minertom opened this issue Dec 24, 2020 · 10 comments
Open

How does nn.conv2D implement the feature map table of LeNet-5? #16

minertom opened this issue Dec 24, 2020 · 10 comments

Comments

@minertom
Copy link

minertom commented Dec 24, 2020

I have been going through the pytorch documentation of conv2D. Reading the docs from pytorch I see

torch.nn.Conv2d(in_channels: int, out_channels: int, kernel_size: Union[T, Tuple[T, T]], stride: Union[T, Tuple[T, T]] = 1, padding: Union[T, Tuple[T, T]] = 0, dilation: Union[T, Tuple[T, T]] = 1, groups: int = 1, bias: bool = True, padding_mode: str = 'zeros')

From the LeNet paper of November 1998 I see that the third convolution layer is implemented with 6 input layers and 16 output layers. The 16 output layers are made from a combination of the 6 input layers according to a table, also in the paper:

LenetFeatureMap

From the chapter 5 tutorial, C3 is implemented with

lenet.add_module('C3', nn.Conv2d(in_channels=6, out_channels=16, kernel_size=5))

What I do not see is how pytorch implements this feature map table. It seems a little like a "loaves and fishes" issue :-).

P.S. If I might kill two birds with one stone, can i ask which plots are being implemented with IPython? I have observed that usually the plots that you generate are implemented in the plots directories from each chapter, using matplotlib. I was looking for HTML plots that were generated with IPython, because you call the IPython.core.display module and import display, HTML. But, I could not seem to spot how it was used.

Thank You
Tom

@dvgodoy
Copy link
Owner

dvgodoy commented Dec 27, 2020

Hi Tom,

The PyTorch implementation of C3 layer is a "reinterpretation" if you will of the original paper. It does not reflect the fancy customized column assignment of the depicted Table 1. I guess LeCun did it like that back then to try to squeeze some performance out of it - not something we need to be concerned anymore.

Regarding the IPython imports, I've only used them in the very first cell of the notebook to make it wider - if you're running it locally, it will make visualization a bit nicer, but that's all there is to it.

Best,
Daniel

@minertom
Copy link
Author

minertom commented Dec 27, 2020 via email

@dvgodoy
Copy link
Owner

dvgodoy commented Jan 14, 2021

Hi Tom,

Just published a new chapter :-)
Not sure if you're receiving notifications from Leanpub, so I thought of letting you know here.
Have fun!

Best,
Daniel

@minertom
Copy link
Author

minertom commented Jan 15, 2021 via email

@minertom
Copy link
Author

minertom commented Jan 15, 2021 via email

@dvgodoy
Copy link
Owner

dvgodoy commented Jan 15, 2021

Hi,

Thanks for your comment on my writing style, that means a lot to me :-)

Regarding the LinearAlgebra module: I've developed this package as base for the ML Fundamentals course, but it was kinda "hacky" so I've uploaded it to PyPI only (but not GitHub).

If you install it using pip install intuitiveml, you should be able to import the LinearAlgebra module and use it as you like.

Also, the code for "intuitiveml" is open, you can download its source from PyPI here: https://pypi.org/project/intuitiveml/#files

Hope it helps.

Best,
Daniel

@minertom
Copy link
Author

minertom commented Jan 19, 2021 via email

@dvgodoy
Copy link
Owner

dvgodoy commented Jan 20, 2021

Hi Tom,

I don't have a video course yet, but it is definitely in my plans for 2021 after I finish the book.

Regarding SVMs, I guess you've already gone through the corresponding notebook in ML Fundamentals (https://github.com/dvgodoy/ML_Fundamentals/blob/master/13.%20Support%20Vector%20Machine%20(SVM).ipynb)?

There isn't much to it actually: it is a glorified linear regression. The trick is, you want to have all points in the positive class to have the "predicted y" being 1 or more, while all points in the negative class must have their "predicted y" being -1 or less. The +1/-1 is completely arbitrary. Moreover, you want two points, the extremes of each class, to be exactly 1 and -1. There is one set of weights for the "y = w1x1 + w2x2 +..." that makes that happen (IF the points are separable by a straight line).

Since most real problems won't be separable like that, you need to find a compromise between this linear regression and the points that are trespassing. That's a soft margin, and you control how soft/hard it is by using the C multiplier on the penalty of the trespasser points.

Then there is the kernel trick, which is just a fancy way of applying a function to all the features (usually polynomials) to increase dimensionality and make the points more easily separable. The kernel trick itself is just a mathematical shortcut to avoid actually computing these transformations. Roughly speaking, it is like: the function of the dot product yields the same result as the dot product of the function.

Why dot product, right? Again, fancy mathematical thing... minimizing the weights of that linear regression is equivalent to a different optimization problem that involves computing dot products for all pairs of data points.

SVMs are a clever way of addressing nonlinearities in datasets, especially before NNs and activation functions became the norm. For some reason, it is still common to see them used in medicine/healthcare, but not so much anywhere else (that I know of).

I am not sure if that's what you were looking for... is there any other specifics you were interested in?

Best,
Daniel

@minertom
Copy link
Author

minertom commented Jan 21, 2021 via email

@minertom
Copy link
Author

minertom commented Jan 22, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants