diff --git a/docs/capsule_networks/index.html b/docs/capsule_networks/index.html index 68dbb22b..20c6028e 100644 --- a/docs/capsule_networks/index.html +++ b/docs/capsule_networks/index.html @@ -3,12 +3,12 @@
- + - + @@ -18,7 +18,7 @@ - +This is a PyTorch implementation/tutorial of Dynamic Routing Between Capsules.
-Capsule networks is neural network architecture that embeds features +
Capsule network is a neural network architecture that embeds features as capsules and routes them with a voting mechanism to next layer of capsules.
Unlike in other implementations of models, we’ve included a sample, because it is difficult to understand some of the concepts with just the modules. -This is the annotated code for a model that use capsules to classify MNIST dataset
+This is the annotated code for a model that uses capsules to classify MNIST datasetThis file holds the implementations of the core modules of Capsule Networks.
I used jindongwang/Pytorch-CapsuleNet to clarify some confusions I had with the paper.
-Here’s a notebook for training a Capsule Networks on MNIST dataset.
+Here’s a notebook for training a Capsule Network on MNIST dataset.
@@ -351,12 +351,12 @@ The length of each output capsule is the probability that class is present in th \lambda (1 - T_k) \max(0, \lVert\mathbf{v}_k\rVert - m^{-})^2$T_k$ is $1$ if the class $k$ is present and $0$ otherwise. -The first component of the loss is $0$ when if the class is not present, -and the second component is $0$ is the class is present. +The first component of the loss is $0$ when the class is not present, +and the second component is $0$ if the class is present. The $\max(0, x)$ is used to avoid predictions going to extremes. $m^{+}$ is set to be $0.9$ and $m^{-}$ to be $0.1$ in the paper.
The $\lambda$ down-weighting is used to stop the length of all capsules from -fallind during the initial phase of training.
+falling during the initial phase of training.137class MarginLoss(Module):
Internal covariate shift will adversely affect training speed because the later layers -($l_2$ in the above example) has to adapt to this shifted distribution.
-By stabilizing the distribution batch normalization minimizes the internal covariate shift.
+($l_2$ in the above example) have to adapt to this shifted distribution. +By stabilizing the distribution, batch normalization minimizes the internal covariate shift.
It is known that whitening improves training speed and convergence. Whitening is linearly transforming inputs to have zero mean, unit variance, @@ -95,9 +95,9 @@ and be uncorrelated.
Normalizing outside the gradient computation using pre-computed (detached) means and variances doesn’t work. For instance. (ignoring variance), let -where $x = u + b$ and $b$ is a trained bias. -and $\mathbb{E}[x]$ is outside gradient computation (pre-computed constant).
-Note that $\hat{x}$ has no effect of $b$. +where $x = u + b$ and $b$ is a trained bias +and $\mathbb{E}[x]$ is an outside gradient computation (pre-computed constant).
+Note that $\hat{x}$ has no effect on $b$. Therefore, $b$ will increase or decrease based $\frac{\partial{\mathcal{L}}}{\partial x}$, @@ -106,14 +106,14 @@ The paper notes that similar explosions happen with variances.
Whitening is computationally expensive because you need to de-correlate and the gradients must flow through the full whitening calculation.
-The paper introduces simplified version which they call Batch Normalization. +
The paper introduces a simplified version which they call Batch Normalization. First simplification is that it normalizes each feature independently to have zero mean and unit variance: where $x = (x^{(1)} … x^{(d)})$ is the $d$-dimensional input.
The second simplification is to use estimates of mean $\mathbb{E}[x^{(k)}]$ and variance $Var[x^{(k)}]$ from the mini-batch -for normalization; instead of calculating the mean and variance across whole dataset.
+for normalization; instead of calculating the mean and variance across the whole dataset.Normalizing each feature to zero mean and unit variance could affect what the layer can represent. As an example paper illustrates that, if the inputs to a sigmoid are normalized @@ -126,8 +126,8 @@ where $y^{(k)}$ is the output of the batch normalization layer.
like $Wu + b$ the bias parameter $b$ gets cancelled due to normalization. So you can and should omit bias parameter in linear transforms right before the batch normalization. -Batch normalization also makes the back propagation invariant to the scale of the weights. -And empirically it improves generalization, so it has regularization effects too.
+Batch normalization also makes the back propagation invariant to the scale of the weights +and empirically it improves generalization, so it has regularization effects too.
We need to know $\mathbb{E}[x^{(k)}]$ and $Var[x^{(k)}]$ in order to perform the normalization. @@ -136,7 +136,7 @@ and find the mean and variance, or you can use an estimate calculated during tra The usual practice is to calculate an exponential moving average of mean and variance during the training phase and use that for inference.
Here’s the training code and a notebook for training -a CNN classifier that use batch normalization for MNIST dataset.
+a CNN classifier that uses batch normalization for MNIST dataset.x
is a tensor of shape [batch_size, channels, *]
.
-*
could be any number of (even 0) dimensions.
+*
denotes any number of (possibly 0) dimensions.
For example, in an image (2D) convolution this will be
[batch_size, channels, height, width]
Sanity check to make sure the number of features is same
+Sanity check to make sure the number of features is the same
174 assert self.channels == x.shape[1]