Closed aashikazim closed 2 years ago
Does learn.predict
work for you?
Hi @aashikazim, If I recall correctly,clf.get_X_preds
expects a list of items. In order to the the correct dimension for a single item list, try using clf.get_X_preds(X[splits[0:1]], y[splits[0:1]])
Hi @aashikazim, If I recall correctly, clf.get_X_preds expects a list of items. In order to the the correct dimension for a single item list, try using clf.get_X_preds(X[splits[0:1]], y[splits[0:1]])
Exactly. All you need to do is to pass the sample with a shape [1 x n vars x seq length]. If you have a 2d array (X_sample) you can just use X_sample[None].
Hi, @williamsdoug and @oguiza. Thanks for answering my question. I tried your suggestion. I don't know why it is not working in my side. Please have a look at my code if I am doing anything wrong?
@vrodriguezf , thank you for the suggestion. I also tried that, it produced an error.
Hi @aashikazim. @oguiza has created a great set of tutorials for tsai located in the tutorial_nbs
folder. You might want to look at 01_Intro_to_Time_Series_Classification which contains a section Inference on additional data located near the bottom of the notebook. Try running the tutorial notebook on Google Colab and verify the the dimension of the inference data in Oguiza's example and the dimensions of your data are similar.
You may need to update to the most recent version of tsai. If you can upgrade to the latest version in GitHub using: pip install git+https://github.com/timeseriesAI/tsai.git
Hi @aashikazim, If I recall correctly, clf.get_X_preds expects a list of items. In order to the the correct dimension for a single item list, try using clf.get_X_preds(X[splits[0:1]], y[splits[0:1]])
Exactly. All you need to do is to pass the sample with a shape [1 x n vars x seq length]. If you have a 2d array (X_sample) you can just use X_sample[None].
Hi @oguiza , I am also trying to Inference "one sample":
single_tstensor_X = single_tstensor_X[None,:]
#TSTensor(samples:1, vars:6, len:36, device=cuda:0)
test_ds = dataloaders.dataset.add_test(X=single_tstensor_X)
test_dl = valid_dl.new(test_ds)
test_probas, test_targets, test_preds = learn.get_preds(dl=test_dl, with_decoded=True, save_preds=None, save_targs=None)
That's not an comfortable way to make inference. Would you like to add a 1-line wrapper function to make inference easier? Thanks
There's no need to do that. All you need is:
test_probas, test_targets, test_preds = learn.get_X_preds(X_test) # X_test is a 3d numpy array [n_samples x n_vars x seq_len]
Please, take a look at the documentation about inference.
Understood. Many thanks!
I'll close this issue based on the last comment. Please, reopen if necessary.
I was trying to do inference with only one sample at a time with the following provided code.
But it gives the following exception. Would you please suggest me a solution?
"Could not do one pass in your dataloader, there is something wrong in it"
Btw, I was getting the correct result for the provided sample.