--- title: Inference keywords: fastai sidebar: home_sidebar summary: "This contains the code required for inference." description: "This contains the code required for inference." nb_path: "nbs/052a_inference.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

Learner.get_X_preds[source]

Learner.get_X_preds(X, y=None, bs=64, with_input=False, with_decoded=True, with_loss=False, save_preds=None, save_targs=None, concat_dim=0)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
from tsai.data.external import get_UCR_data
dsid = 'OliveOil'
X, y, splits = get_UCR_data(dsid, split_data=False)
X_test = X[splits[1]]
y_test = y[splits[1]]
{% endraw %} {% raw %}
learn = load_learner("./models/test.pth")
{% endraw %} {% raw %}
test_probas, test_targets, test_preds = learn.get_X_preds(X_test, with_decoded=True)
test_probas, test_targets, test_preds
(tensor([[0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1917, 0.2858, 0.3510],
         [0.1717, 0.1917, 0.2857, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1917, 0.2859, 0.3509],
         [0.1715, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1917, 0.2859, 0.3509]]),
 None,
 array(['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
        '4', '4', '4', '4'], dtype='<U1'))
{% endraw %} {% raw %}
test_probas2, test_targets2, test_preds2 = learn.get_X_preds(X_test, y_test, with_decoded=True) # This test fails on torch==1.10.0
test_probas2, test_targets2, test_preds2
(tensor([[0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1917, 0.2858, 0.3510],
         [0.1717, 0.1917, 0.2857, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2858, 0.3510],
         [0.1716, 0.1917, 0.2859, 0.3509],
         [0.1715, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1916, 0.2858, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3509],
         [0.1716, 0.1916, 0.2859, 0.3510],
         [0.1716, 0.1917, 0.2859, 0.3509]]),
 TensorCategory([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
         3, 3, 3, 3, 3, 3]),
 array(['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
        '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4',
        '4', '4', '4', '4'], dtype='<U1'))
{% endraw %} {% raw %}
from fastcore.test import test_eq
test_eq(test_probas, test_probas2)
test_eq(test_preds, test_preds2)
{% endraw %}