Error Running Trained Binary Classifier Structured Model


(Aldrin) #1

I’ve successfully trained a structured data model on the UCI Occupancy dataset and am running into issues when I attempt to predict for a single row of data (versus my batch size - 64 rows).

I have been following this link to deploy my model into a microservice but am unable to even get the model to predict after saving and loading it with PyTorch.

In addition to attaching my notebook, the steps I am taking are:

  1. Load PyTorch Model
    learn2 = torch.load(‘notify_min_v1.1.pt’)
  2. Load test dataset and grab next cat and cont tensors.
    cat = V(next(iter(md.test_ds.cats)))
    cont = V(next(iter(md.test_ds.conts)))
  3. Passing the cat and cont variables to the model to predict.
    preds2 = learn2(cat, cont)

Full notebook: https://drive.google.com/file/d/1oGZtmIShIOT-LlryL0co8gIebBnQz76X/view?usp=sharing


(Sam Lloyd) #2

Hey @buzz_aldi
Looks good, the only thing you need to do is reformat your array dimensions for cat and cont
learn.model takes batches from data.trn_dl, so when you pass just a single value to it, it needs to be put in the format as if it were a batch.
so going from
cont.shape of [9] to cont.shape of [1,9]

This can simply be corrected by learn2(cat[None,:], cont[None, :] )

Let me know how that works