Hello everybody,
fastai version 1.0.40 is used
For some reason in my code, I’ve 4 images that are already present as object of type: fastai.vision.image.Image
I would like to make predictions not on those images 1 by 1 but on a small batch of these 4 images to speed up the inference.
I would like to know if it is possible to use the “get_preds” or “pred_batch” with a list of images, and not from a folder contening different images in .jpg format for example.
The idea was to do something like:
img4Inference = ImageItemList.? to load the 4 images, then:
model.data = img4Inference to change the data “associated” to the model, then:
model.get_preds(ds_type=DatasetType.Test)
Until now I didn’t find a way to create this ImageItemList from the 4 images, neither with the add_test function.
The problem is that only the first image has a filename.
img1 = open_image(imgFileNamePath) --> type is fastai.visdion.image.Image
This is how I create img2, img3 and img4:
img2 = Image(tensor.flip(2)) --> type is fastai.visdion.image.Image
img3 = Image(tensor.flip(1)) --> type is fastai.visdion.image.Image
img4 = Image(tensor.transpose(1,2)) --> type is fastai.visdion.image.Image
What I’m doing is a king of “controled” TTA (as I’ve understood it)
I can do prediction with a loop, image by image:
imgList = [img1, img2, img3, img4]
for img in imgList:
prediction = model.predict(img)
But what I want to do is to make prediction on these 4 images as a mini batch from their current state.
It won’t be a good idea I think to save the 4 images in a folder, then “reload” them as test set (mini batch)
You will have to create your batch yourself then. Use data_collate, this is the function that is used (almost) every time to collate the images in a batch.