Is it possible to change the dimensions of torch::jit::script::Module using only Libtorch (C++)?

I want to perform transfer learning using Libtorch (C++).
At that time, I think about using a trained model (for example, 1000 classifications of Resnet50), but I want to change the number of output classifications each time.

Please tell me how to change the dimension of the final layer of torchscript only with Libtorch for testing in a C++ environment without Python.

As long as you can save the dimension-changed model with jit::model, I can handle the rest.

that’s all. thank you.