Traditionally, the portrait mode effect has been achieved using 2 lenses which detect objects present in the foreground and in the background. With advances in the field of ML, this effect can also be implemented using only image segmentation.
Check out this link for further details - https://github.com/mayank26saxena/portrait-mode