Load raw image data without image extension

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

The easiest way would be to write your own Dataset and implement the loading in __getitem__.
The Data loading tutorial might be a good starting point.
Basically you would provide the paths to all *.dat files in your __init__, and use them in __getitem__ to load a single sample.

Let me know, if you get stuck somewhere.

Thank you! I finally complete importing the data.