  The goal of this paper is to develop a machine learning model to analyze the
main gravitational lens and detect dark substructure (subhalos) within
simulated images of strongly lensed galaxies. Using the technique of image
segmentation, we turn the task of identifying subhalos into a classification
problem, where we label each pixel in an image as coming from the main lens, a
subhalo within a binned mass range, or neither. Our network is only trained on
images with a single smooth lens and either zero or one subhalo near the
Einstein ring. On an independent test set with lenses with large ellipticities,
quadrupole and octopole moments, and for source apparent magnitudes between
17-25, the area of the main lens is recovered accurately. On average, only 1.3%
of the true area is missed and 1.2% of the true area is added to another part
of the lens. In addition, subhalos as light as $10^{8.5}M_{\odot}$ can be
detected if they lie in bright pixels along the Einstein ring. Furthermore, the
model is able to generalize to new contexts it has not been trained on, such as
locating multiple subhalos with varying masses or more than one large smooth
lens.
