## 2 Materials and Methods  
The optical setup built to collect the datasets for training the DNNs is shown in Figure 1. The beam of a wavelength-tunable laser source (M-squared, SolsTiS 2000 PSX XF with Terascan software), emitting in the range 700-1000 nm is used to illuminate a graded-index (GRIN) MMF with 62.5 \(\upmu\)m core diameter and numerical aperture (NA) of 0.275 (GIF625, Thorlabs GmbH, Germany). The wavelength of the laser source can be tuned with 10 fm accuracy. GRIN fibers are often used to avoid temporal distortion in a signal due to modal dispersion. A beam expansion is achieved by a set of lenses (L1: \(f\) = 200 mm, OBJ1: 10\(\times\), Newport, Irvine, CA, USA) placed at the laser output to ensure that the beam size is large enough to illuminate optimally a phase-only spatial light modulator (SLM, 1920 \(\times\) 1080 pixels, Pluto-Vis, Holoeye, Berlin, Germany). The SLM is used to display the desired patterns and the SLM plane is imaged onto the proximal facet of the MMF by means of a 4f imaging system (lens L2:\(f\) = 400 mm, microscope objective OBJ2: 60x, Newport, Irvine, CA, USA). Another 4f system (the same as the proximal one, L3-OBJ3) magnifies the speckle pattern emerging from the distal facet on a CCD camera (CCD, Chameleon 3, 1024 \(\times\) 1280 pixels, Mono, Point Grey). An additional lens (L4: \(f\) = 200 mm) in 2f configuration allows monitoring the images generated by the SLM on a second camera at the proximal side (CCD2). A halfwave plate is placed before the SLM to ensure that the correct polarization of illumination is used (see Figure 1). The fiber length used in the experiments is 10 cm.  
Figure 1: Optical setup for the collection of the image dataset used for training the DNN algorithms. (L = lens, OBJ = microscope objective, HWP = half-wave plate, M = mirror, BS = beam splitter).  
The dataset used to assess the performance of the DNN is generated by projecting phase images of handwritten digits at the proximal fiber side [16; 17; 18; 20]. These images are available online in the MNIST database, which is widely used to test the capabilities of different neural network architectures [28]. Wavelength drifting is simulated by a Matlab code written to control the laser wavelength, the speckle acquisition by the camera CCD1 (Figure 1) and the input images on the SLM. We first choose the wavelength range of the drift in the code and then a random array with 100 wavelength values within this range is generated. The wavelength values are sorted in an ascending order because this leads to a more stable operation of the tunable laser instead of tuning the wavelength to far spaced wavelength values. Moreover, the laser stabilization at the specified wavelength is much faster. The inputs are therefore projected on the proximal fiber facet in batches of 100, each one at a specific wavelength. For the next 100 inputs, the random wavelength array is recalculated so that we always get randomly different wavelength values for the images of the full dataset. We collected a total of 10,000 intensity images of speckle patterns. The speckle images captured by CCD1 are cropped to \(1024\times 1024\) pixels and then downsampled to \(32\times 32\) pixels before being imported in the DNN code.  
For the classification experiments, a VGG(Visual Geometry Group)-type DNN is used with an architecture described in Figure 2[29]. We use mean squared error (MSE) as a loss function and an Adam optimizer with a learning rate of \(1\times 10^{-4}\). The DNN is trained in batches of 100 images for a maximum of 50 epochs. The collected images of the dataset are split so that 80% are used for training, 10% for validation and 10% for testing. For each one of the collected datasets the DNN training is repeated five times to obtain the standard deviation values. The VGG classifier is implemented in Tensorflow 1.5 Python library on a computer equipped with an NVIDIA GeForce GTX 1080 Ti graphics processing unit.