# Smart Detection System of Safety Hazards in Industry 5.0
## 4 Flexible and Adjustable Detection System
### AI Model Creation
#### 4.2.2 AI Model Evaluation  
One of the most crucial steps in the creation of an AI model is to evaluate the performance of the trained model. The evaluation not only measures the efficacy of the trained model but also can provide insights about the quality of training data as well as indications for potential enhancements regarding the dataset generation procedures. The main goal of our evaluation process is to determine the suitability of the synthetic dataset for training an AI model effectively. Specifically, via the evaluation procedure, we can discover whether the synthetic dataset can be used to successfully train a model.  
The evaluation of AI models can be achieved by quantitative metrics as well as by qualitative processes. Metrics such as Intersection over Union (_IoU_), Precision, Recall, and Average Precision (_AP_) procure quantitative insights, while the visual inspections of predicted bounding boxes provide qualitative indications. In the case of object detection tasks, the predictions of the AI model are bounding boxes accompanied by class labels. Having this in mind, it becomes essential to adopt appropriate evaluation metrics to assess the performance of object detectors and the utility of a synthetic dataset for this task. In this study, the evaluation metrics that are utilized to determine the effectiveness of trained models on synthetic datasets are Average Precision (_AP_) and Mean Average Precision, as well as visual inspection of predictions.  
The Intersection over Union (_IoU_) measures the localization accuracy of an AI object detector. Specifically, the _IoU_ calculates the amount of overlap between the predicted and the ground truth bounding boxes. In object detection, the AI model may predict multiple bounding boxes for each object. Based on the IoU and a chosen threshold, predictions can be categorized as true positives (_TP_), false positives (_FP_), or false negatives (_FN_). In practice, the _IoU_ threshold is often set at 0.5. Utilizing this categorization, the precision and recall values are calculated based on Equations (2) and (3), respectively.  
\[Precision=\frac{TP}{(TP+FP)} \tag{2}\]  
\[Recall=\frac{TP}{(TP+FN)} \tag{3}\]  
Consequently, based on those values, the precision-recall curve is designed. The numerical representation of this curve is given by the Average Precision (_AP_) in Equation (4). _AP_ is computed for each object class and represents the weighted mean of precisions at each threshold with the increase in recall. A high _AP_ value indicates both high precision and recall, while a lower _AP_ suggests a decline in either precision or recall across a range of confidence thresholds.  
\[AP=\int_{r=0}^{1}p(r)dr \tag{4}\]  
where \(r\) is the recall and \(p(r)\) is the precision as a function of recall.  
An extension of the Average Precision is the Mean Average Precision (\(mAP\)), which gives the precision for the entire model. The \(mAP\) is determined by taking the average of the \(AP\) for all the classes \(N\), Equation (5).  
\[mAP=\frac{1}{N}\ \sum_{i=1}^{N}AP_{i} \tag{5}\]