I implemented the resnet18 variant of the network by myself, and defined the’forward’ function in the network. My model can be trained on the computer normally, but when I save the model according to the method written in the pytorch Android tutorial, I got the error “Method’forward’ is not defined.”. I want to know what is the problem.
Here is my code：
model = multi_resnet18_kd(first_channel=1, num_classes=50)
model.eval()
example = torch.rand(1, 1, 200, 68)
traced_script_module = torch.jit.trace(model, example)
print(traced_script_module)
optimized_traced_model = optimize_for_mobile(traced_script_module) # There is an error when running here
optimized_traced_model.save(“model.pt”)