Hi everyone,
I’ve followed the first part of the course and built a model to detect sleeves length in clothes.
I managed to run the model on my test folder and get labeled predictions in a list.
Problem is, it seems like the predictions comes out shuffled and so i cannot know which picture in the test folder the predictions refer to.
Let me explain this further. When i pass the first image (00000000.jpg) of the test folder into the model i basically get a different prediction than the first result displayed after running get_preds() on the whole test folder.
To get the prediction of only the first image i simply use:
file = '/content/drive/My Drive/fastai/test/00000000.jpg'
img = open_image(file)
pred = my_trained_mod.predict(img)
pred
result: 'sleeveless’
To get the predictions list from the whole test folder i use:
preds,_ = my_trained_mod.get_preds(ds_type=DatasetType.Test)
labels = np.argmax(preds, 1)
test_predictions = [data.classes[int(x)] for x in labels]
Then i take only the first prediction:
test_predictions[0]
result = 'long sleeves’
As you can see, the first prediction on top of the list of predictions does not match the single prediction on ‘00000000.jpg’, which is the first picture in my test folder…
How do I somehow get my list of predictions match the order of the images in my test folder?
UPDATE
I was able to solve the issue since download_images() give an ascending number to images downloaded and it’s very helpful. In order to get the test predictions in order i used this code where 191 is the number of pics in my test folder (192)
path = '/content/drive/My Drive/fastai/test'
test_predictions = []
for i in range(0,191):
if i < 10:
file = '/content/drive/My Drive/fastai/IC2/test/0000000'+str(i)+'.jpg'
elif i < 100:
file = '/content/drive/My Drive/fastai/IC2/test/000000'+str(i)+'.jpg'
else:
file = '/content/drive/My Drive/fastai/IC2/test/00000'+str(i)+'.jpg'
img = open_image(file)
single_pred = my_trained_mod.predict(img)[0]
test_predictions.append(single_pred)
test_predictions