Hi Alan,
When I changed
log_preds = learn.predict(is_test=True)
log_preds.shape
I am getting this error
TypeError Traceback (most recent call last)
in ()
1 # this gives prediction for validation set. Predictions are in log scale
----> 2 log_preds = learn.predict(is_test=True)
3 log_preds.shape
~/fastai/courses/dl1/fastai/learner.py in predict(self, is_test)
253 self.load(‘tmp’)
254
→ 255 def predict(self, is_test=False): return self.predict_with_targs(is_test)[0]
256
257 def predict_with_targs(self, is_test=False):
~/fastai/courses/dl1/fastai/learner.py in predict_with_targs(self, is_test)
257 def predict_with_targs(self, is_test=False):
258 dl = self.data.test_dl if is_test else self.data.val_dl
→ 259 return predict_with_targs(self.model, dl)
260
261 def predict_dl(self, dl): return predict_with_targs(self.model, dl)[0]
~/fastai/courses/dl1/fastai/model.py in predict_with_targs(m, dl)
130 if hasattr(m, ‘reset’): m.reset()
131 res =
→ 132 for *x,y in iter(dl): res.append([get_prediction(m(*VV(x))),y])
133 preda,targa = zip(*res)
134 return to_np(torch.cat(preda)), to_np(torch.cat(targa))
TypeError: ‘NoneType’ object is not iterable
I have downloaded plant species dataset from kaggle and trying to train a model and predict the species for the test datatset.
I have used the same code as used for cats dogs classification.
Since this a multi label classification,do I need to change my code anywhere.
arch=resnet34
data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
learn.fit(0.01, 50)
This is the label for a val data
data.val_y
How to get labels for test data?
preds = np.argmax(log_preds, axis=1) # from log probabilities to 0 or 1
probs = np.exp(log_preds[:,1]) # pr(dog)
Predictions are in log scale. For binary classification we are converting it to be in between 0 and 1. For multi label classfication problems,how should we convert the predictions in to corresponding labels for test data?