# Optimal CNN-Hopfield Network for Pattern Recognition Based on a Genetic Algorithm +
## 1 Introduction  
In the last decade, convolutional neural networks (CNNs) have become the standard methods for pattern recognition and image analysis. Indeed, they have provided highly successful advances in image classification problems [1; 2; 3]. CNNs are auto-encoders, which means that they encode or extract features automatically with any specific fitting [4; 5]; this characteristic has increased their utilization in computer vision tasks, such as semantic segmentation tasks [6; 7; 8; 9], image retrieval [10; 11; 12], and object detection [13; 14; 15]. However, one of main problems regarding their use in industrial systems comes from the computation time and the use of memory resources. This is because classic CNN-based architectures have at least one fully connected layer (FC) depending on the architecture's depth [16; 17]. Figure 1 illustrates some popular examples of CNN models, where it can be clearly seen that the FC layer(s) contains most of the parameters of the network [1]; for instance, AlexNet [18] has about 64 million learnable parameters, and 91.56% of these parameters belong to the last three FC layers of the model; the same observation applies to the Lenet5 [19], VGG16 [1], and VGG19 [1] models. The majority of learnable parameters are in their FC layers, with 89.18%, 89.58%, and 86.11%, respectively, out of the total number of parameters that can be learned.  
In the literature, some authors, such as those of [20], proposed the replacement of the FC layer with an associative memory bank. Indeed, this use of memory overcame the problems related to backpropagation; the features extracted from the CNN layers werestored in the memory and then recovered at the inference phase. However, the storage capacity of the memory scheme remains a serious problem to be solved.  
To deal with this problem, many authors have proposed alternatives to the classical neural network learning rules, such as in [21; 22; 23], and they have provided valuable information on the properties of attention heads in transformer architectures [24]. The contributions of this paper can be summarized in the following:  
* New hybrid CNN-RNN (recurrent neural network) architecture and approach and its optimization.
* Inference acceleration of a CNN-based architecture.
* Formulation of the optimization of the architecture as a knapsack problem.  
The architecture uses a pretrained CNN classification model to extract feature maps from the input images. The use of an associative memory bank (the Hopfield neural network) allows the replacement of the fully connected layer and, therefore, the large number of trainable weights (parameters) while preserving the performance. In order to increase the storage capacity and minimize the effects caused by the spurious states, several Hopfield networks are used in parallel.  
In the following, in Section 2, we present an overview of the framework, while in Sections 3 and 4, the classical Hopfield model and a detailed description of the new formulation of the problem are presented. In Sections 5 and 6, the dataset used for the experimentation and the discussion of the obtained results are presented. Finally, the paper is concluded in Section 7.