I am wondering if there is a way to generalize the approach to make predictions on a list of images and not just a single one.
I know I could accomplish the task by making a function and looping through all the images I want to predict on, but it seems to me that the fastai library is smarter than that and probably already has a method to do what I want.
Thanks @AjitB. However, I think that in your suggested approach, the “test” images in the learn object are the images used during training. In my case, I want to predict on a new set of images which were not available during trainig, so they were not passed on to the learn object.
I did figure out a way to do what I want, which essentially is to create a new data object as follows:
The key changes in this code was that the test_name variable inside the get_data2 function now points to a new directory with my new images.
One “problem” with this approach is that I am not applying TTA to the new predictions, which is not ideal. I am still trying to figure out how to do that. Any thoughts?
Does anyone know how to update the learn object without training? In essence, I want to update the test images in it to my new set of images, so that I can call learn.TTA to make predictions?
I figured it out…
It is just a matter of doing learn.set_data(get_data2(sz,bs)), and point the get_data fucntion to the directory with the new test data, and then just follow the process as detailed in the notebook, that is:
log_preds, y = learn.TTA(is_test=True) probs = np.mean(np.exp(log_preds),0)
Hi @reyemarr,
I have verified that the images in the test folder are not used for training or validation.
It can be confirmed by looking at the values of the following:
data.train_ds
data.valid_ds
data.test_ds
len(data.train_ds) + len(data.valid_ds) = Number of images in the train folder
len(data.test_ds) = Number of images in the test folder
Definition of the ‘class ImageDataBunch’ can be found here:
The definition of the fit method can be found here: