# A Deep Learning Based Dislocation Detection Method for Cylindrical Crystal Growth Process
## Proposed Method
### Detection Method
In order to accurately label the images, the contrast of the original image is enhanced to avoid misjudgment or omission due to the image being too dark. Before sending an image into the model, it is resized with the annotation frame to avoid oversized images causing insufficient resources, and the uint8 type image is normalized to the float type of [-1.0, 1.0]. 2. ResNet-50 is used to extract the feature map of the input image, and then the feature map is passed to the subsequent RPN network;
3. The RPN network is used to generate candidate boxes of feature maps, perform classification and bounding box regression: 1. Classification: use softmax to determine whether anchors belong to the foreground (disappeared habit line or normal one) or background. 2. Bounding box regression: modify anchors with bounding box regression on the feature map to generate preliminary proposals. 4. RoI pooling: proposals are mapped to feature maps, and the mapped areas are pooled into proposal feature maps of uniform size, and then they are fed to the fully connected (FC) layer to determine the target category. 5. Final classification: the final category of proposal feature maps is judged, and the position of the bounding box is again corrected by bounding box regression. 6. According to the position and category of the image target frame, if there exists a disappeared habit line and a normal one together, which corresponds to the special case, bounding boxes close to each other will be merged, and the target will be judged as normal. The model adopts approximate joint training, the loss function is composed of two parts: (1) loss of RPN which includes classification loss distinguishing whether the anchor is the target and regression loss generated from the proposals; (2) loss of last-stage Fast R-CNN including classification loss determining final category and regression loss of the proposals' accurate bounding boxes. The loss function of RPN network can be described as follows:  
\[L(p_{i},t_{i})=\frac{1}{N_{cls}}\sum_{i}L_{cls}\Big{(}p_{i},p_{i}^{*}\Big{)}+ \lambda\frac{1}{N_{reg}}\sum_{i}p_{i}^{*}L_{reg}\Big{(}t_{i},t_{i}^{*}\Big{)} \tag{1}\]  
Figure 7: The detection framework. where \(i\) is the index of an anchor in a mini-batch, and \(p_{i}\) is the predicted probability of anchor \(i\) being an object. The ground truth \(p_{i}^{*}=1\) (if the anchor is positive) when intersection over union (IOU) of the anchor [i] and the marked ground truth box is greater than the threshold (0.7 in the model), \(p_{i}^{*}=0\) (if the anchor is negative) when it is less than the threshold (0.3 in the model). This means that the regression loss function is only activated when the candidate box is foreground. \(t_{i}=\left\{t_{x},t_{y},t_{w},t_{h}\right\}\) is a vector representing the 4 parameterized coordinates of the predicted bounding box, and \(t_{i}^{*}\) is that of the ground-truth box associated with a positive anchor. \(N_{cls}\) represents the number of anchors in a mini-batch, \(N_{reg}\) represents the number of anchor locations. \(\lambda\) is the weight used to balance classification and regression loss, the classification loss \(L_{cls}\) is log loss over two classes (object vs. not object), the regression loss \(L_{reg}\big{(}t_{i},t_{i}^{*}\big{)}=smooth_{L1}\big{(}t_{i}-t_{i}^{*}\big{)}\), where the loss function \(smooth_{L1}\) can be described as follows:  
\[smooth_{L1}(x)=\left\{ \begin{array}{l}0.5*x^{2},\;|x|<1\\ |x|-0.5,\;\textit{otherwise}\end{array} \right. \tag{2}\]  
In the subsequent Fast R-CNN stage, classification of final category and regression of accurate position of the prediction frame are performed, the loss function is defined as:  
\[L(p,u,t^{u},v)=L_{cls}(p,u)+\lambda[u\geq 1]L_{loc}(t^{u},v) \tag{3}\]  
Compared with the loss function of RPN network, \(L_{cls}(p,u)\) is the multiclassification loss that divides the final category of the target box, and the regression part \(L_{loc}(t^{u},v)\) still uses the \(smooth_{L1}\) loss function.