Fastai inference: Do you need to call cnn_learner before load_learner?

(xnet) #1

I’m having issues following the docs on fastai inference:

In my work, I just start out by creating a learner object from load_learner, but there is no data attached to it. The examples in the docs assumes you create the ML model and than load the learner, so it combines both training and inferencing together - but then you need to remember what model you loaded during training, which kind of defeats the purpose of exporting the model. Am I missing something?

Alternatively, is there a way to pass the data object to a learner object without calling cnn_learner?



why would you need your training data? when you are using load_learner you are using it for inference. Could you elaborate more on the reason why you are using load_learner?


(xnet) #3

I’m using it for inference, and if you don’t load the data, there is no data for it to run predictions for. The “training data” in this case is the test data.



You can either predict single images using the predict method, or you can add a test set using the test argument for load_learner. See this tutorial for more information:


(xnet) #5

I can use learn.predict, but that is very slow. So I’m trying to get it to work on learn.get_preds. I recall having issues adding test set to my segmentation models, that’s why I’m trying to add it as a “training set”.



Just create your DataBunch. Then set the data attribute to your DataBunch: = data

Then predict using get_preds:

preds = learn.get_preds()