AI Algorithm Development Flow
AI algorithm development is mainly carried out according to the following flow.
| Step | Phase | Description |
|---|---|---|
| 1 | Overview | Understand the overall flow of AI algorithm development. |
| 2 | Requirement analysis | Organize the functions to be implemented and clarify the required sub-algorithms. |
| 3 | Data preparation | Collect diverse data required for training, and perform appropriate annotation and preprocessing. |
| 4 | Model selection | Select an appropriate model structure according to accuracy, speed, and application. |
| 5 | Model training | Train the model using frameworks such as TensorFlow, PyTorch, and Caffe. |
| 6 | Model conversion | Convert the trained model into RKNN format, and perform quantization and pre-compilation. |
1. Overview
AI algorithm development is not a single task. It is a series of processes that includes requirement organization, data preparation, model selection, training, and model conversion for the target runtime environment.
By designing each phase properly, developers can build AI models that balance accuracy and processing speed for real application scenarios.
2. Requirement Analysis
Algorithm functions are often expressed in short terms, such as “face recognition,” “driver behavior detection,” or “customer behavior analysis in commercial facilities.”
In practice, however, the final function is often achieved by combining multiple sub-algorithms in sequence. This is because each sub-algorithm uses a different neural network structure and is optimized for its own function.
| Model category | Function |
|---|---|
| Object detection model | Detects whether a target object exists in an image and outputs its coordinates. It may also provide classification at the same time. |
| Keypoint detection model | Detects a specific target in an image and outputs keypoints such as skeleton points or facial organ positions. |
| Similarity comparison model | Compares the similarity between two different individuals. It is used for face recognition, pig face recognition, product recognition, and similar applications. |
| Segmentation model | Detects objects in an image and segments them into irregular pixel regions according to contours or other criteria. It may also include classification. |
| OCR model | Recognizes characters. |
The following are examples composed of multiple sub-algorithms.
Example A: Face Recognition Algorithm
A face recognition algorithm consists of the following sub-algorithms.
- Face detection model (detection model)
- Face pose correction model (keypoint detection model)
- Face comparison model (similarity comparison model)
Example B: Driver Behavior Detection Algorithm
A driver behavior detection algorithm consists of the following sub-algorithms.
- Face recognition algorithm
- Recognition of dangerous behaviors such as smoking or using a smartphone (detection model)
- Drowsy driving detection (keypoint detection model)
- Lane departure detection (detection model)
Example C: Commercial Facility Analysis
Commercial facility analysis consists of the following sub-algorithms.
- Face recognition algorithm
- Human body tracking algorithm (detection model + similarity comparison model)
Only after the required processing phases are clarified can data collection, model optimization, and model training be performed in line with the target requirement.
3. Data Preparation
For many people, data preparation may look like a monotonous and repetitive task. However, this phase contains many important points that require attention.
Diversity of Data Samples
Data samples must be sufficiently diverse. Sample diversity is the basis for ensuring the generalization capability of an algorithm.
For example, when developing an agricultural product recognition function, if only images of red apples are collected and used for training, it will be difficult for the model to recognize green apples accurately.
A sufficient number of negative samples is also required. If only agricultural product images are provided to a neural network, it is difficult to expect the trained network to effectively distinguish real apples from plastic apples.
To improve algorithm reliability, special situations that may occur in real application scenarios must be fully considered and added to the training data.
Compressibility of Data Samples
The size of each sample has a major impact on the execution efficiency of the network model.
As long as the required effect can be maintained, the image size should be compressed as much as possible to improve processing efficiency. For example, under the same environment, a 112×112 pixel image may be processed about four times faster than a 224×224 pixel image.
On the other hand, complete images may be required in some cases to avoid loss of image information. For example, wildfire detection requires a high recall rate, and excessive image compression may reduce the recall rate and degrade algorithm performance.
Appropriate Annotation and Preprocessing
Data requires appropriate and accurate annotation and preprocessing.
Data annotation greatly affects the upper limit of the performance that training can achieve. If there are too many incorrect labels, it becomes difficult to obtain effective training results.
Data preprocessing refers to applying certain processing in advance so that machines can understand the data more easily.
For example, when representing where an agricultural product is located in an image, the expression “the center point is at the 200th pixel from the left” is intuitive and accurate. However, when the image size changes, the pixel position difference becomes large, which may make learning more difficult.
Therefore, the distance should be normalized, for example as “the center point is located at 40% of the image width from the left.”
Preprocessing for audio data is even more diverse. Differences in word segmentation methods, Fourier transforms, and other processing methods can affect training results.
Data Preparation Continues Throughout Development
Data preparation does not necessarily have to be complete at the beginning.
If a model achieves a certain effect after training but still has some defects, the training data can be supplemented or optimized, and the existing model can be retrained to correct the problems.
Even in later optimization phases, adding appropriate images is often the most effective way to improve performance.
Therefore, data-related review and optimization should continue throughout the development process. It is not sufficient to focus on data sample issues only at the beginning of development.
4. Model Selection
Usually, even when implementing the same function, there are multiple candidate models. Each model has different characteristics in terms of accuracy and computation speed.
Models are mainly discovered and improved through academic research, public competitions among companies, and similar activities. Therefore, developers need to continuously review papers and articles about new AI models.
At the same time, accumulating and analyzing existing models is also very important. The following table shows examples of relatively good model structures for each function.
| Model type | Model name | Effect | Speed |
|---|---|---|---|
| Detection model | yolov5 | High accuracy | Medium |
| Detection model | ssd | Medium accuracy; recognition of small objects is average | Fast |
| Keypoint detection model | mtcnn | Average accuracy; detects a small number of keypoints | Fast |
| Keypoint detection model | openpose | High accuracy; detects many keypoints | Medium |
| Similarity comparison model | resnet18 | High accuracy | Fast |
| Similarity comparison model | resnet50 | High accuracy, strong robustness, and high resistance to disturbance | Medium |
| Segmentation model | mask-rcnn | Medium accuracy; can segment irregular object regions in an image | Slow |
5. Model Training
Developers with AI development experience can train models using familiar general-purpose frameworks such as TensorFlow, PyTorch, and Caffe.
Our development kit can convert models trained with these frameworks into models dedicated to EASY EAI Nano-TB.
6. Model Conversion
After developing a custom model with TensorFlow, PyTorch, Caffe, or similar frameworks, the model must first be converted into an RKNN model.
Usually, model quantization and pre-compilation are also performed to improve execution efficiency.