The persistent diagram (from persistent homology) can be used to get a vector that can uniquely encode shape information. check readme of this repo : https://github.com/GUDHI/TDA-tutorial/tree/master, for example you can look into this simple shape detection pipleine, https://colab.research.google.com/drive/1Dk2d7kqcVJMHWCXq1VMPS0oeYgp5-NOL?usp=sharing
Thanks for the question. The code for shape prediction in neural networks is not fixed universally; there are common architectures and methods used nonetheless. For example, SPNet is a fully convolutional neural network for shape prediction (Xiao et al.). It is very effective in medical image segmentation. This network outputs a shape parameter vector by processing image patches and comparing those to the ground truth shapes, results optimized via layers such as convolutional layers and an Euclidean distance-based loss function. There are variations in this architecture that depend on the tasks at hand, such as object detection or more concrete scientific applications.
Xiao, Y., Liu, D., Zhang, J., Liu, Y., & Zhan, S. (2021). SPNet: Shape Prediction Using a Fully Convolutional Neural Network. Artificial Life and Robotics, 26(1), 100–109.