Once you have trained learn, you can use
learn.get_preds() to get the validation
This will give you a list with 2 tensors inside it. The first tensor is the predictions and the second is the true values.
If you are trying to get predictions from test, you can instead use
This will give you the predictions in the first tensor and all 0s in the second tensor.
Assuming you used this line:
preds = learn.get_preds(is_test=True)
preds would give you the output of something like this:
tensor([[ 2.6747, -1.6915, -2.7530, ..., -0.0572, 1.0603, 2.3969],
[ 0.2564, -0.1261, 1.7345, ..., 2.5312, 1.3247, 3.9575],
[ 0.0725, -1.2854, 5.8897, ..., 1.8020, 4.0222, 0.0308],
[ 2.7146, -0.2381, -1.7115, ..., -1.4560, -0.7291, 3.7035],
[ 0.6296, -1.2794, 1.8849, ..., 3.3482, 2.1478, 2.8770],
[ 3.9928, 0.3684, 2.3774, ..., 3.2413, 1.2406, 3.8148]])
Each row of this would be a prediction for each class so you want to know which number is the highest for each row. You can do this with argmax like so:
class_guess = preds.argmax(dim=1)
The other thing is I think you may be using ImageDataBunch.from_df a bit incorrectly. Instead of using it like that, you should add the test to the earlier databunch. If for some reason you had to do things like this, you would need to pull the train_dl out of test_data (since that is where you put your test set) and feed that into the learn.validate function so it would look like this
learn.validate(test_data.train_dl) I’m not quite sure what that learn.data = test_data is doing so maybe it is doing what you want it to.
Edit: some of what I said earlier may have been incorrect about how you are using the test_df. It looks like from_df has a test available to pass, but it is looking for a folder of images, not a dataframe. I’d be curious to see what your test dataframe looks like, maybe I could help implement that if test is a dataframe instead of a Path.
Edit2: I’m re-evaluating my knowledge of learn.validate because it didn’t do what I expected it to. Basically everything I told you is wrong so back to the drawing board for me. I think this will work potentially (still testing though)
test_results = get_preds(learn.model, test_data.train_dl)