  Detecting substructure within strongly lensed images is a promising route to
shed light on the nature of dark matter. However, it is a challenging task,
which traditionally requires detailed lens modeling and source reconstruction,
taking weeks to analyze each system. We use machine-learning to circumvent the
need for lens and source modeling and develop a neural network to both locate
subhalos in an image as well as determine their mass using the technique of
image segmentation. The network is trained on images with a single subhalo
located near the Einstein ring across a wide range of apparent source
magnitudes. The network is then able to resolve subhalos with masses $m\gtrsim
10^{8.5} M_{\odot}$. Training in this way allows the network to learn the
gravitational lensing of light, and remarkably, it is then able to detect
entire populations of substructure, even for locations further away from the
Einstein ring than those used in training. Over a wide range of the apparent
source magnitude, the false-positive rate is around three false subhalos per
100 images, coming mostly from the lightest detectable subhalo for that
signal-to-noise ratio. With good accuracy and a low false-positive rate,
counting the number of pixels assigned to each subhalo class over multiple
images allows for a measurement of the subhalo mass function (SMF). When
measured over three mass bins from $10^9M_{\odot}$--$10^{10} M_{\odot}$ the SMF
slope is recovered with an error of 36% for 50 images, and this improves to 10%
for 1000 images with Hubble Space Telescope-like noise.
