I have followed the tutorial to load the image data
image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x))  for x in ['0', '1']}

where data_dir is the directory of all the images.
The situation is that my data is already in the form of matrix, namely, the data file is written as the grayscale value of each pixel. The extension of the data is ‘dat’. But ImageFolder prevents me from loading any file besides jpg,png, etc.
Obviously, I could first export the grayscale image from raw data and then import the grayscale image again, but this seems really redundant since I already have the grayscale data in the first place. Therefore, is there any method I can directly import the grayscale matrix data? Any comments and idea are appreciated! Thanks