# Approach to Automated Visual Inspection of Objects Based on Artificial Intelligence
## 3 Visual Inspection Methodology and Data Processing Design
### Object Detector and Training Options  
In order to detect objects using neural networks in images, several methods can be used in MATLAB software [29]. Within the solution of the problem of this work, the most used object detectors YOLO, ACF, SSD, R-CNN, R-FCN, ACF and its variations were considered. From previous experience and further research ongoing at the department, the use of the R-CNN detector seems to be a suitable approach for these testing purposes.  
Although this type of detector has several disadvantages compared to other algorithms, such as longer training time and the associated problematic use in real-time applications, its advantages are an excellent ability to detect even small objects, and in conjunction with the use of the Transfer Learning method, its relatively simple implementation. This makes it a suitable choice for the purpose of fulfilling the aim of this research.  
The applied R-CNN model consists of four basic steps:  
* Selection of expected areas of interest;
* Extraction of elements using a deep convolutional neural network;
* Classification of elements using the selected model;
* Marking the classified elements in the image with a bounding boxes.  
After loading and appropriate editing of input data, training settings were defined. A pre-prepared \"optimization algorithm\" called stochastic gradient descent with momentum (SGDM) was used in this process, and adjusted values of some training parameters were added to it. Major modifications of the chosen deep neural network were described above, but there was also need to change some of training options, to reach required level of prediction precision. Selected parameters are:  
* 'MiniBatchSize', 32, the default value SGDM setting of 128 and represents a subset of training data intended for subsequent evaluation of the network training and adjustment of weights.
* 'InitialLearnRate', 1e-6, which was changed from 0.01 to 0.000001. The smaller the value of this parameter, the longer the training takes, but the network should achieve better results under favorable conditions.
* 'MaxEpochs', 10, specifies the maximum required number of epochs where an epoch represents one whole course of the algorithm training on the training set.  
The code written in Matlab R2020a was subsequently applied on real data obtained by scanning the tire surface using a selected industrial camera under predefined conditions. The test images were not included in the training phase in order to verify the real functionality of the system and thus created for the detection of selected types of defect. R-CNN detector was trained for each one of the chosen defects, using 60 images with a given type of individual defect. The architecture of the convolutional neural network for object detector was developed on an AlexNet pre-trained network basis, in a similar way to [29], available in Deep Learning Toolbox(tm) of Matlab/Simulink (Mathworks). Transfer Learning was used via the replacement of the last three layers by new layers to perform net training for our task and to obtain final network architecture and a setup suitable for our object detector (see Figures 12 and 13). The last layer (Fc8) provides the final decision-making for individual defects CH01-CH06.