## 2 Materials and Methods
### Fire Prevention and Fire Detection
#### 2.2.1 Image Classification  
When it comes to fire detection using a visual camera, the main goal was to create a dataset that can be used to train, validate, and test custom or existing convolutional neural network (CNN) architectures that can detect fire in input images. The first task was to create a dataset for training. Due to the lack of proper datasets, we had to create a new one. That was accomplished by obtaining publicly available datasets in addition to images scraped from the Internet. The final dataset used for training consists of 50,972 non-fire images and 7359 fire images. The validation dataset consists of 3000 non-fire images and 3000 fire images, and the test dataset consists of 2000 and 2000 images of non-fire and fire, respectively. The evaluated CNNs include various implementations of ResNets, MobileNets, and EfficientNets. ResNets represent the oldest evaluated type of CNNs, whereas MobileNets and EfficientNets are more recent. The best-performing networks out of the four crafted network tiers on the stated dataset include ResNet-101 [25], MobileNetV3-Large variant [26], and EfficientNet-B3 [27]. All evaluated models were trained for 120 epochs, which indicated the number of passes of the entire training dataset that the evaluated model completed. The complete testing methodology, together with training parameters, is available in [28]. The main evaluation metrics of focus were recall and F1-score calculated from the entries in the confusion matrix. Recall is a measure of how many of the positive cases (fire) the classifier correctly predicted as a fire over all the positive cases in the dataset. The recall represents the most important metric because we do not want to misclassify a fire event as a non-fire event, which can lead to extensive or total property damage and has a very high chance of claiming human lives. The F1-score metric was chosen to have a balanced overview of the overall performance of a given model, as it is defined as the harmonic mean of precision and recall. The metrics for all four tiers (L1-L4) of the evaluated networks for the first 60 epochs can be seen in Figure 5. On the designed dataset, a similar conclusion can be derived when looking at all four tiers. EfficientNet outperformed MobileNet, which was close behind. In comparison to other examined networks, Base ResNet exhibited its aging characteristics with poor recall and a low F1-score measure. The similarities between MobileNet and EfficientNet are due to the fact that EfficientNet scales the network width, depth, and input-image resolution in addition to including numerous components from the complete MobileNet network stack. As can be expected, the best results were achieved with network models evaluated in the L4 tier. In Figure 6, the number of parameters, number of operations, and size on disk are presented to visually compare the complexity and required computational power for each tested model. It is shown that all ResNet models had the lowest performance but also the largest number of parameters as well as size on disk, which makes them least suitable for embedded usage. In Figure 7, there are several image examples from our test dataset along with the achieved results of the best-performing model, EfficientNet-B3. The image in Figure shows the actual class, the class predicted by CNN, and the network's confidence. Figure 5: Recall and F1-score of all four tiers (**L1**–**L4**) of the evaluated networks. Figure 6: Comparison of all models by number of operations, number of parameters, and model size, on disk. In Figure 7b,e there are some examples in which the network wrongly classified images. Figure 7b is a very challenging image since the flame is very small and barely visible. In the same image, the Figure 7a network correctly classified the image as a fire, but that is due to the sun, which is very bright and is fire colored, thus leading to the network mistaking it as fire.