Fastai v1.0.5 Can I use different KIND of sources for train, validation and test datasets?

Is it possible to train and validate the model with data loaded from folder as png images (ImageList.from_folder()), but then do testing (inference) with completely different source (which retains the same image format/size/normalization)?

Longer version:
I am implementing a model for Kaggle MNIST competition. The data there is provided as pixel arrays in csv file. This is a custom format which is not supported by Therefore, I’ve converted given data into actual png files in corresponding “training”, “validation” folders and then loaded them simply using ImageList.from_folder(…).
All goes well, the model gets trained. But when I want to test my trained model, I’d like to use csv format (as provided in Kaggle MNIST competition) instead of converting testing data into png files. Is that possible without additional programming?
When trying to load test dataset using MyCustomCsvImageList(ImageList).from_df(some_test_images.csv) I get error similar to this: “FileNotFoundError: [Errno 2] No such file or directory: ‘./0’”. From the error looks like the code still wants to load data as it were png files, but what I want is to load data from that given pixel data from csv.

This is how I try it:…some required params…))

from_df here is my custom implementation which works perfectly fine to load csv data for train and validation sets.

So, this problem makes me wonder, is it just me or is there some buggy behavior in Fastai lib preventing the usage of different kind of input data sources?

Not sure for v1.0.5, but if you’re using v3:

Using the csv directly without additional programming doesn’t seem to be possible, since from_df just looks at a specified column to see which path it loads the image from. See comment in:

That said, I think it should be possible to use data from the CSV by doing:

  1. Read a row, and create a torch.tensor object from it, reshape and stack it to make it (3, 28, 28)
  2. Pass said tensor as: vision.image.Image(tensor) -> to create an image object
  3. Pass said image object as: learner.predict(image)

I’ve taken a similar approach, except I’ve also converted the test data into png files written to the disk. My work is here if it helps anyone:

1 Like