tsai icon indicating copy to clipboard operation
tsai copied to clipboard

how to save tsai model and load in libtorch C++

Open MichaelCarrik opened this issue 4 months ago • 1 comments

  1. I am trainning model in python like this

            model= tsai.LSTM_FCNPlus(train_dsets.vars, train_dsets.c, train_dsets.len, se=8)
            learn = tsai.Learner(train_dsets, model, metrics=[tsai.mae, tsai.rmse])
            learn.fit(80, learnRate *0.9,cbs=[EarlyStoppingCallback(patience=7), ShowGraphCallback()]
                       )
           torch.jit.trace(model,).save("model.pt")
           predict1 =  learn.get_X_preds(inputs)
    
  2. I load model which step 1 save in libtorch c++ like this

    module = torch::jit::load("model.pt");
    predict2 =   module.forward(inputs).toTensor();
    

I can ensure they have same weights.
however predict1 is not same as predict2 . can anyone tell me correct way  how to save tsai model and load in c++, appreciatlly

MichaelCarrik avatar Jun 13 '25 09:06 MichaelCarrik