This paper presents a new method based on neural networks to optimize the first eigenvalues of second-order elliptic and fourth-order biharmonic operators subject to geometric constraints. These models can have applications in material design for drums and plates. Our approach tackles this problem by developing two neural networks for the eigenfunction and the density function, respectively. A strategic construction infuses empirical experience into the density function, enhancing the algorithm’s robustness and efficiency. Automatic differentiation enables the algorithm to directly obtain the optimization direction instead of solving the eigenvalue problem as traditional optimization methods did. The algorithm, which is executable on a GPU, ensures efficiency aligned with GPU developments. Numerical examples substantiate the effectiveness of the algorithm.