Abstract: NeurODEs are a special type of neural networks that incorporate shortcut connections, enabling their training to be interpreted as an optimal control problem. Our work encompasses two main aspects. Firstly, we consider the mean-field formulation of the problem and derive first-order optimality conditions in the form of a mean-field Pontryagin Maximum Principle. This result is based on a generalized version of the Lagrange multiplier theorem on convex sets of spaces of measures, and it provides a unique and Lipschitz continuous control solution. Secondly, we extend this well-established model to the case of Autoencoders, a specific type of neural network used for data compression and reconstruction. For Autoencoders, we propose a novel architecture and an alternative training method based on the Pontryagin Maximum Principle. To illustrate the effectiveness of our approach, we present informative and easily understandable numerical examples that provide valuable insights into the resulting algorithm.