# Classification of Defective Fabrics Using Capsule Networks
## 3 Method
### Network Model
#### 3.2.1 Capsule Networks  
Convolutional neural networks (CNN) have created great contributions to the machine learning domain. In many classification task domains, CNN's have proven very successful. However, CNN's have some shortcomings that should be taken into account [40]. The basic problem in CNN is that they are translation invariant. This translation invariance problem means keeping the information in a spatial hierarchical manner. More simply, the problem in CNN is to keep the dependent components of an image that must be stored together and in a particular hierarchical form in a random structure. This basic problem is also called the lack of translation equivariance. The lack of translation equivariance in CNN's case is manifest when the network incorrectly assigns the input to a different category label, resulting in false negatives. The second problem in CNN is that they require a large dataset to generalize the network. This is due to the fact that CNN requires a large amount of training data to compensate for the information loss caused by the pooling process [40]. The third problem is the poor imitation of the human visual system. As presented by [PERSON] et al., the closer the simulations of artificial systems to the human visual system, the better the system will perform [41]. To overcome all these problems, CapsNets is an alternative to CNN. As presented by [PERSON], CapsNet is different from traditional CNN. These differences lie in the use of vectors instead of scalar values, no pooling operations, a novel activation function for capsules, and the feed-forward training of capsule parameters unlike the back-propagation in CNN. A comparison between capsules and traditional neurons is given in Figure 5.  
Figure 4: Representative data augmentation process. A CapsNet is a new CNN form used to provide information about the spatial/presence relationship of features (such as scales, locations, orientations, brightness, etc.) in an image. The foundation of this network is based on the addition of concepts called \"capsules\" to CNN. A capsule is a group of neurons that include not only the probability of a particular object's presence but also different informative values related to instantiation parameters such as rotation, pose, posture, slope, position, direction, thickness, scale. Unlike CNN components like pooling and convolution, which cause information loss, capsules are capable of holding more information. The innovation in CapsNets is the \"routing by agreement\" concept, which is replaced with pooling. Based on this concept, outputs are sent to all parent capsules in the next layer, however, their coupling coefficients are not the same. Each capsule tries to estimate the output of the parent capsules, and if this estimate matches the actual output of the parent capsule, the coupling coefficient between these two capsules increases. Considering \(u_{i}\) as the output of capsule \(i\), its prediction for parent capsule \(j\) is computed as  
\[\hat{u}_{j|i}=W_{ij}u_{i} \tag{1}\]  
where \(\hat{u}_{j|i}\) is the prediction vector of the output of the \(j\)th capsule in a higher level computed by capsule \(i\) in the layer below, and \(W_{ij}\) is the weighting matrix that needs to be learned in the backward pass. Based on the degree of confirmation between the capsules in the layer below and the parent capsules, coupling coefficients \(c_{ij}\) are calculated using the following softmax function  
\[c_{ij}=\frac{\exp(b_{ij})}{\sum_{k}\exp(b_{ij})} \tag{2}\]  
where \(b_{ij}\) is the log probability that whether capsule \(i\) should be coupled with capsule \(j\) and its initially set to zero at the beginning of the routing by agreement process.