# A Metaheuristic Harris Hawks Optimization Algorithm for Weed Detection Using Drone Images
## 3 Proposed Framework
### Harris Hawks Optimization Algorithm  
Data-driven AI models are represented by three major components: the data they use, the parameters used to train them, and the architecture of the networks they use. To perform tasks with maximum efficiency, any deep-learning model must achieve a proper balance among these elements. To confirm the design of the model, a set of initial parameters is used in several trials, and the performance of the model is measured within each trial. Additionally, there are optimization concerns associated with increasing network depth. Furthermore, incorrect selection of hyperparameters may result in suboptimal results. The hyperparameter tuning and result analysis for DenseHHO can be a time-consuming process. Consequently, the process of hyperparameter optimization must be performed to iteratively search for the most optimal values based on the training data and update them accordingly. The Harris Hawk Optimization algorithm (HHO) [40; 41] is a metaheuristic optimization method used for the DenseHHO framework. HHO was inspired by [PERSON] hawks' hunting behavior. The HHO algorithm can solve various optimization problems, including function optimization, feature selection, and parameter optimization for machine-learning models. To implement the algorithm, the following steps must be taken. A significant difference between HHO and other optimization algorithms lies in the introduction of the concepts of elite and non-elite hawks instead of following a strict hierarchical structure. As a result, elite hawks take the lead in the search process, representing the fittest solutions. To maintain their position, they mimic the behavior of the best hawks in the population. In this manner, the algorithm can converge toward promising solutions using this exploitation mechanism. Three types of hunting behavior are observed in Harris hawks:  
* Exploration: Hawks fly randomly to discover new areas in which they can search. * Exploitation: Hawks attempt to improve upon the solutions provided by the most successful individuals. * Intensification: Hawks coordinate their efforts to search for prey. Algorithm 1 provides the detailed steps of the proposed DenseHHO framework. After initializing the pre-trained model, the HHO will be used to optimize the network hyperparameters. To search for an optimal solution, the HHO uses the following hunting behavior:  
\[X_{i}^{t+1}=X_{i}^{t}+rand().(X_{j}^{t}-X_{k}^{t}), \tag{3}\] \begin{table}
\begin{tabular}{c c c} \hline \hline
**Layer (Type)** & **Output Shape** & **Param \#** \\ \hline Input\_2 (InputLayer) & [(None, 256, 256, 3)] & 0 \\ sequential (Sequential) & [(None, 256, 256, 3)] & 0 \\ densenet121 (Functional) & (None, 8, 8, 1024) & 18,321,984 \\ flatten (Flatten) & (None, 65,536) & 0 \\ dense (Dense) & (None, 128) & 15,728,768 \\ Dense\_1 (Dense) & (None, 2) & 258 \\ \hline Total params: 34,051,010 & & \\ Trainable params: 33,821,954 & & \\ Non-trainable params: 229,056 & & \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The DenseNet-201 Model Structure. where \(rand()\) is a random number between 0 and 1, \(j\) and \(k\) are two randomly chosen hawks, and \(t\) is the current iteration. The hawks guide the optimization process by updating their positions in accordance with those of other hawks using the following:  
\[X_{i}^{t+1}=\frac{(X_{i}^{t})+(X_{j}^{t})}{2}+rand().(X_{j}^{t}-X_{k}^{t}), \tag{4}\]  
```
0: Weed Images Dataset Dt, CNN- Hyperparameters, Objective Function F
0: best model architecture, Performance Metrics. 1: Create TestDataset, and trainDataset;
2: Set Dimension \(d\), optimization iteration \(T_{[max]}\), and objective function Accuracy
3:for trainDataset portion Tt do
4: Train TLD using DenseNet-121 and DenseNet-201. 5: Initialize a population \(P\) of \(n\) hawks with random positions \(X_{i}\), where \(i=1,2,\ldots,n\). 6: Create solution \(SL_{0}\leftarrow\) InitialPopulationGeneration. 7: Set \(t\gets 0\) an initial optimization step, Counter C\(\leftarrow\) 1,DimensionList DL[ ].