How to get image file names along with predictions (state Form)?


I trying to save the predictions for the state Form competition. I’ve got everything except the image files to attach the right column of the predictions.

in below snapshot i have copied the code from Part1 v1 notebook but i need the test_filenames array filed with fille names.

so question is how do i get the image names via fastai library? I can of course read from the directory but I fear they might have a different listing order than what the fastai library has read.

Another question in Lesson 2 there is this line which fetches next mini batch.

x,y = next(iter(data.val_dl))

But if this fetches only one next mini batch, wont we need a loop to iterate through all the batches? how can it loop through all batches with just one “next” call?


1 Like

next is supposed to return the next element of the iterator object untill all the elements have been received.. It's just a python's shorthand..
This might clarify

1 Like

I got the test predictions using :

predictions= learn.predict(is_test=True)
preds2 = np.exp(predictions) 
preds3= np.round(preds2,1)

But I am quite low in the Kaggle ranking (bottom 5% :frowning: ). I am wondering how can i improve the accuracy. as the fit shows, the accuracy is at 98.6 which is not bad.


however what i find strange is that instead of a cosine LR format, the curve is quite asymmetric. Anyone knows why, and if this is a bad thing ?

G’Day :wink:

I usually use something like this:

submission = pd.DataFrame({‘file’: os.listdir(f’{PATH}test’), ‘label’: pred_classes})

or you could use something like this: