Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add learner.predict() usage example #3842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions nbs/13a_learner.ipynb
Expand Up @@ -231,8 +231,7 @@
"source": [
"`file` can be a `Path` object, a string or an opened file object. If a `device` is passed, the model is loaded on it, otherwise it's loaded on the CPU. \n",
"\n",
"If `strict` is `True`, the file must exactly contain weights for every parameter key in `model`, if `strict` is `False`, only the keys that are in the saved model are loaded in `model`.",
"\n",
"If `strict` is `True`, the file must exactly contain weights for every parameter key in `model`, if `strict` is `False`, only the keys that are in the saved model are loaded in `model`.\n",
"You can pass in other kwargs to `torch.load` through `torch_load_kwargs`."
]
},
Expand Down Expand Up @@ -3804,9 +3803,9 @@
"metadata": {},
"source": [
"It returns a tuple of three elements with, in reverse order,\n",
"- the prediction from the model, potentially passed through the activation of the loss function (if it has one)\n",
"- the decoded prediction, using the potential <code>decodes</code> method from it\n",
"- the fully decoded prediction, using the transforms used to build the `Datasets`/`DataLoaders`"
"- probs[] = the model's predictions (output layer), potentially passed through the activation of the loss function (if it has one)\n",
"- ndx = the decoded prediction, using the potential <code>decodes</code> method from it\n",
"- label = the fully decoded prediction, using the transforms used to build the `Datasets`/`DataLoaders`."
]
},
{
Expand Down Expand Up @@ -3842,7 +3841,11 @@
"dec = 2*out #decodes from loss function\n",
"full_dec = dec-1 #decodes from _Add1\n",
"test_eq(learn.predict(inp), [full_dec,dec,out])\n",
"test_eq(learn.predict(inp, with_input=True), [inp,full_dec,dec,out])"
"test_eq(learn.predict(inp, with_input=True), [inp,full_dec,dec,out])\n",
"\n",
"# Example usage:\n",
"# label,ndx,probs = learner.predict(inp)\n",
"# print( f\"Predicted: {label} with probability {probs[ndx]}\" )"
]
},
{
Expand Down Expand Up @@ -4219,6 +4222,18 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down