Objective With the rapid development of ultrashort pulsed laser technology, the applications are expanding in scientific and technological fields. Passively mode-locked lasers based on nonlinear polarization rotation (NPR) technology are favored due to their simple structure, high damage threshold, and ability to generate ultrashort pulses. However, passively mode-locked fiber lasers based on NPR technology are highly sensitive to polarization states, which limits their application. The development of artificial intelligence technology provides a new way to solve this problem. Usually, researchers use pulse signals to judge the mode-locked state of the laser, but this may ignore spectral information, which is critical to the laser. In this study, a convolutional neural network (CNN) image classification model and an adaptive genetic algorithm (AGA) are combined to achieve automatic mode-locking of fiber lasers. The mode-locking state of the laser is judged by the CNN model by learning the various spectral images of different laser states. Then the electric polarization controller (EPC) is adjusted automatically by the AGA to optimize the polarization state until mode-locking is achieved. This approach provides a new way to realize automatic mode locking. Methods By combining CNN and AGA, we propose a new method to achieve automatic mode-locking based on laser spectral image features. In the experiment, spectral image data of the laser is collected automatically by a computer-controlled commercial spectrometer, which is then used to create a data set of a binary classification CNN model. Spectral image features of the laser are extracted and analyzed to classify the mode-locking state through the training CNN model. The classification results are used as the fitness value in AGA. The adaptive mechanism of AGA can significantly accelerate the convergence process, thereby enhancing the efficiency of achieving mode-locking. AGA evaluates the fitness of individuals in each generation and selects the fittest individual for retention. Highly adaptive individuals are selected using the 'roulette-wheel' method, after which they are subject to adaptive crossover and mutation to generate new individuals. These new individuals, together with the selected fittest individual, form the next generation of the population. The new generation needs to be re-evaluated for fitness. The process is iterated until the mode-locked state is established. Results and Discussions A passively mode-locked fiber laser based on the NPR technique is built, which contains a laser diode pump, a wavelength-division multiplexer, an erbium-doped fiber, an EPC, a polarization sensitive isolator, a manual polarization controller, and an optical coupler (Fig. 1). The spectral images output from the laser are collected by a commercial spectrometer. A binary CNN classification model is built based on these data [Fig. 3(a)]. The accuracy of the CNN model is 98.0%. The typical spectral images of mode-locking and non-mode-locking output from the laser are shown (Fig. 4). The fitness values of spectral images of mode-locking states are close to one, while the values are close to zero for the non-mode-locking state. The mode-locking state is achieved when the pump power is set to 300 mW. The typical optical spectrum, oscilloscope trace, and autocorrelation trace are shown (Fig. 5). The output of the laser is a typical stretched pulse with the central wavelength, pulse duration, and round trip time of 1560 nm, 7.329 ps, and 113.6 ns. To verify the effectiveness of the proposed method, 40 independent tests are conducted with the pump power and manual polarization controller fixed (Fig. 6). The average number of generations required to adjust from random states of the laser to mode locking is 5.4. To verify the ability of the laser to recover after loss of locking, 10 tests are made by randomly changing the polarization of the MPC three times, respectively (Fig. 7). Conclusions We propose an automatic mode-locking method based on the CNN image classification model and AGA. The method enables the passive mode-locked fiber laser to automatically judge, establish and recover the mode-locked state of the laser. By analyzing the spectral image data output from the laser, we can judge and classify mode-locked states and non-mode-locked states by the CNN model with high accuracy. Mode-locked states can be reliably achieved from the random state of the laser, using the AGA to adjust the polarization of EPC. In the experiment, 40 tests are conducted. The average number of generations required to adjust from random states of the laser to mode locking is 5.4. Moreover, the applicability of the method is also verified by randomly changing the manual polarization controller. This work provides a new scheme to realize the automatic mode-locking technique.