I understand how Fast AI define test set. Test set is meant to be unlabelled. However, I have a trained a model with ResNet18 and split my train set into 80:20. Now, I have the model trained, and wanted to evaluate the model with completely new, unseen data. How can I achieve that? All the topics similar to this question are from 2018-2019 and some of the function is not available in v2.
What I came up with is as follows:
import os
for i in range(10):
v,s=0,0
for filename in os.listdir('/content/AUC-DDD-v2/v2/test/c{}'.format(str(i))):
if filename.endswith(".jpg"):
probs, _ = learn.get_preds(dl=learn.dls.test_dl(filename, drop_last=False))
if i == torch.argmax(probs).item:
s+=1
else:
v+=1
s+=1
print('class {}: {}'.format(i,(s-v)/s))
My question is, is there an elegant way to solve this instead of using the function above? Thank you.
I’m new to this, but wouldn’t you just export your model, this creates a pickle file of your model, and then open that pickle file for use, such as:
#train your model
learn.export()
.
.
.
#use your model
path = 'C:\HOME\.fastai\data\...\your_model.pkl'
learn = load_learner(path)
is_it_whatever,_,probs = learn.predict(whatever_is_being_checked)
I did this with the “cat” code in 01_intro and it works when I check other pictures with the provided code.
path in this case is Path(“AUC-DDD-v2/v2/test”)
If you specifically want the c, do get_files iteratively over each folder and add them together to merge them.
Predict is the wrong approach here as you’re doing each image individually, and following the other answer, you’re doing it on the CPU as well. The first was slower, the second is even slower.