Python/Pytorch - how to use Image arrays?
I want to put image data in a neural network, but I am having trouble using the Image datatype.
I read my data here using Pytorch;

import torch
import torchvision
import numpy as np
from settings import Settings

class Data_Read:
    @staticmethod
    def getTrain():
        train_dataset = torchvision.datasets.ImageFolder(
            root=Settings.pathTrainImagesCopy,
            transform=torchvision.transforms.ToTensor()
        )
        train_loader = torch.utils.data.DataLoader(
            train_dataset,
            batch_size=64,
            num_workers=0,
            shuffle=True
        )
        return train_loader

    @staticmethod
    def getTest():
        test_dataset = torchvision.datasets.ImageFolder(
            root=Settings.pathTestImagesCopy,
            transform=torchvision.transforms.ToTensor()
        )
        test_loader = torch.utils.data.DataLoader(
            test_dataset,
            batch_size=64,
            num_workers=0,
            shuffle=True
        )
        return test_loader


The following code creates a single dimension column of images;

class Imagez:
    @staticmethod
    def Get(arr):
        imageData = []
        for item in arr:
            filePath = item
            img = Image.open(filePath).convert('LA')
            imageData.append(img)

        return imageData


And these methods are called from the main class as follows;

trainData = Data_Read.getTrain()
testData = Data_Read.getTest()

arrTrain = np.array(trainData.dataset.imgs)[:,0]
labelTrain = trainData.dataset.targets

arrTest = np.array(testData.dataset.imgs)[:,0]
labelTest = testData.dataset.targets

X_Train = Imagez.Get(arrTest)


I find whenever I try to use the Images datatype I in X_Train I get into trouble with error messages. 
For example;

mlp = MLPClassifier(hidden_layer_sizes=(10,10,10), max_iter=1000 )
mlp.fit(X_Train, labelTrain)


Will give me this error message;


  Traceback (most recent call last):   File
  "c:\Users\hijik.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py",
  line 43, in 
      main(ptvsdArgs)   File "c:\Users\hijik.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd__main__.py",
  line 432, in main
      run()   File "c:\Users\hijik.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\lib\python\old_ptvsd\ptvsd__main__.py",
  line 316, in run_file
      runpy.run_path(target, run_name='main')   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\runpy.py", line
  263, in run_path
      pkg_name=pkg_name, script_name=fname)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\runpy.py", line
  96, in _run_module_code
      mod_name, mod_spec, pkg_name, script_name)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\runpy.py", line
  85, in _run_code
      exec(code, run_globals)   File "d:\702\702-Coursework-Task-5\src\Main.py", line 74, in 
      mlp.fit(X_Train, Y_TrainLabels)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py",
  line 981, in fit
      return self._fit(X, y, incremental=(self.warm_start and   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py",
  line 323, in _fit 
      X, y = self._validate_input(X, y, incremental)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py",
  line 919, in _validate_input
      multi_output=True)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py",
  line 719, in check_X_y
      estimator=estimator)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\utils\validation.py",
  line 496, in check_array
      array = np.asarray(array, dtype=dtype, order=order)   File "C:\Users\hijik\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\numeric.py",
  line 538, in asarray
      return array(a, dtype, copy=False, order=order) TypeError: int() argument must be a string, a bytes-like object or a number, not
  'Image'


I am thinking I need to convert my images to another data type. What advice would you give?

EDIT - this is the minimum reproducible error;

X_Train = []
filePath = '..\\images\\Train\\anger\\S010_004_00000014.png'
img = Image.open(filePath).convert('LA')
X_Train.append(img)
Y_TrainLabels = ["0"]
mlp = MLPClassifier(hidden_layer_sizes=(10,10,10), max_iter=1000 )
mlp.fit(X_Train, Y_TrainLabels)


First of all, your Imagez class returns list of PIL images, those cannot be used for training as you need number representations.

Easy fix would be:

import torchvision


class Imagez:
    @staticmethod
    def Get(arr):
        imageData = []
        for item in arr:
            filePath = item
            # This transforms below
            img = torchvision.transforms.functional.to_tensor(
                Image.open(filePath).convert("LA")
            )
            imageData.append(img)

        return imageData


See convert docs and whether you really need it.

Secondly, if you are going for sklearn and it's MLPClassifier, you have transform those arrays into np.array.

For each you can call .numpy() on pytorch tensor to convert it and stack it afterwards into an array.

Furthermore, your inputs and outputs seem to be images, you either have to flatten those into a single vector for fully connected layers or use convolutional neural networks and PyTorch, for example the network below:

import torch

model = torch.nn.Sequential(
    torch.nn.Conv2d(3, 64, kernel_size=3),
    torch.nn.Conv2d(64, 128, kernel_size=3),
    torch.nn.Conv2d(128, 128, kernel_size=3),
    torch.nn.Conv2d(128, 128, kernel_size=3),
    torch.nn.Conv2d(128, 1, kernel_size=3),
)


You could find some basic tutorials on PyTorch website, 60 Minute Blitz seems like a good starting point for you cause there is a lot to fix here.
